tags:

views:

30

answers:

1

hi i want to insert div element 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?

+2  A: 

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>');
});
Reigel
And suddenly, all becomes sense :p
jAndy
@jAndy, yeah, but don't worry, at first I did also got the same assumption and got confused by the OP as you did I guess... and maybe I'm still wrong.. ;)
Reigel