开发者

jquery insert div element which will include all old body content

开发者 https://www.devze.com 2023-01-13 18:12 出处:网络
hi i want to insert div e开发者_如何转开发lement in the root of my page hierarchy, so it must be opened after body tag and closed before body close tag, how can i do it in jquery?you mean like this?

hi i want to insert div e开发者_如何转开发lement in the root of my page hierarchy, so it must be opened after body tag and closed before body close tag, how can i do it in jquery?


you mean like this?

<body>
   <div>
   <!-- old contents -->
   </div>
</body>

you can do it this way,

$(function(){
   $('body').contents().wrapAll('<div>');
});

it seems you have accepted this one so I just want to add something.

you may also add some class to the div you have just added.

like this,

$(function(){
   $('body').contents().wrapAll('<div class="someClass"></div>');
});
0

精彩评论

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

关注公众号