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>');
});
精彩评论