开发者

jQuery nesting DOM nodes > 3 levels deep

开发者 https://www.devze.com 2023-03-27 23:19 出处:网络
Trying to nest newly created DOM nodes 3 levels deep. I\'m using the following code: var dom = $(\'<div>\').append(\'<a>\').append(\'<span>\');

Trying to nest newly created DOM nodes 3 levels deep. I'm using the following code:

var dom = $('<div>').append('<a>').append('<span>');

result of code above:

<div>
     <a></a>
     <span></span> 
</div>

desired 开发者_StackOverflow中文版output:

<div>
     <a>
          <span></span>
     </a>
</div>


var dom = $('<div>').append('<a><span>')


var dom = $('<div />')
              .append(
                  $('<a />')
                      .append(
                          $('<span />')));
0

精彩评论

暂无评论...
验证码 换一张
取 消