javascript - Placing a div within body tag -


currently have page setup as:

<body id="some-id">     <div class="some-class">    </div>    <!-- some-class -->  </body> 

i've tried using append , before, however, it's not quite doing want do.

i'm trying add div id inserted-div this:

<body id="some-id">  <div id="inserted-div">     <div class="some-class">    </div>    <!-- some-class -->  </div> <!-- inserted div -->  </body> 

each time use something, example: $('body').appendto("<div id='inserted-div'>"); either won't insert or insert </div> after inserted <div> rather placing </div> before closing body. tried prepend , prependto no luck.

you looking wrap method.

$('.some-class').wrap('<div id="inserted-div"></div') 

$('body').prepend -- add div first child of body.

$('body').append -- add div last child of body.

but in case want inserted-div wrapper existing div.

check fiddle

to target first instance can either use

$('.some-class').first() or $('.some-class:eq(0)')


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -