views:

80

answers:

1

Couldn't find an answer, but Im trying to get the last ID of the last div that was created on the page. The code I'm using doesn't seem to work using .last(). My syntax is probably wrong but I can't get it to show the ID.

  jQuery(document).ready(function()
    {jQuery("a.more_posts").live('click', function(event){
            jQuery("div[id^='statuscontainer_']").last();
            var id = parseInt(this.id.replace("statuscontainer_", ""));
            alert(id);
       }); 
    });

I figured out to do it this way and this worked.

jQuery(document).ready(function(){  
jQuery("a.more_posts").live('click', function(event){
        jQuery("div[id^='statuscontainer_']:last").each(function(){
        var id = parseInt(this.id.replace("statuscontainer_", ""));
        alert(id);
    }); 
}); 
}); 
A: 

The this.id is going to give you the id of the link that was clicked. I think you want the id of the last container.

jQuery(document).ready(function()  {
       jQuery("a.more_posts").live('click', function(event){ 
            var lastContainer = jQuery("div[id^='statuscontainer_']").last(); 
            var id = parseInt(lastContainer.attr('id').replace("statuscontainer_", "")); 
            alert(id); 
       });  
    }); 
bendewey
Thanks but it didn't work. I was getting a lastContainer is undefined. However, I did figure it out that did work. I edited my post to show what I did.
Pjack