开发者

Get last ID of dynamic div

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("status开发者_StackOverflowcontainer_", ""));
        alert(id);
    }); 
}); 
}); 


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); 
       });  
    }); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜