Search code examples
jqueryajaxlive

how to get the id of the last div, appended with ajax, with jquery?


i have a div with an id by default, then i append some more divs there with a ajax call.

How do i get those id;s with jquery?

for example:

<div class="main">
    <div id="0" class="take">test</div>  <!-- this one is here by default -->

    <!-- added by ajax -->
    <div id="1" class="take">test</div>
    <div id="2" class="take">test</div>
    <!-- end added by ajax -->

    <!-- added by another ajax request -->
    <div id="3" class="take">test</div>
    <div id="4" class="take">test</div>
    <!-- end added by ajax -->

</div>

if i do:

alert($("div.take:last").attr('id');)

i will only get 0. looks like i need to use something like .live... This might be very simple and i just don't see it.

any ideas?

thanks

edit: if a add some divs with a request then i add some more i still get 0


Solution

  • Here is an example of the code working that includes adding new <div>s using jQuery.

    Working Example