javascript - Inserting elements into page using jQuery -


i have empty div on page want insert content using jquery.

for example:

<div class="container"> </div> 

after inserting first lot of content, i'd markup this:

<div class="container">     <div class="inserted first">blah</div> </div> 

round 2 of inserting content i'd be:

<div class="container">     <div class="inserted second">blah</div>     <div class="inserted first">blah</div> </div> 

round 3 of inserting content i'd be:

<div class="container">     <div class="inserted third">blah</div>     <div class="inserted second">blah</div>     <div class="inserted first">blah</div> </div> 

how can achieve using jquery?

so far have tried $(data).appendto($(".container").before(".inserted")); doesn't work.

update: of answers. pretty answers far work. had pick 1 went oldest first. again help.

you want insert content before current child. need prepend() function:

$(".container").prepend(data); // assuming data <div class="inserted second">blah</div> 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -