shortysbest Posted May 22, 2011 Share Posted May 22, 2011 I have a comment page, i use the id from li to load more comments. the structure of my comments are: <ul class='stream'> <li id='1'> <ul class='post-controls' <li id='toggle1'></ul> </ul> </li> <li id='2'> <ul class='post-controls' <li id='toggle2'></ul> </ul> </li> </ul> That's basically how it would look for two comments. Now here's the issue, I'm using jquery to select the last comment on the page so I can get the id of the last loaded comment, to load from there on to the next set of comments. it's an auto loading type of thing. The problem is it's selecting the 2nd set of li id (ul.stream li#2 ul.post-controls li#toggle2) instead of (ul.stream li#2) this is the code: var lastID = $(".stream li:last").attr('id'); Link to comment https://forums.phpfreaks.com/topic/237161-jquery-selecting-last-li-in-the-first-set-of-ul-li/ Share on other sites More sharing options...
JustLikeIcarus Posted May 26, 2011 Share Posted May 26, 2011 Change it to this to keep it from looking inside the nested elements. var lastID = $(".stream > li:last").attr('id'); Pretty much the same, just added a ">" Link to comment https://forums.phpfreaks.com/topic/237161-jquery-selecting-last-li-in-the-first-set-of-ul-li/#findComment-1220673 Share on other sites More sharing options...
cssfreakie Posted May 26, 2011 Share Posted May 26, 2011 apart from it being jquery, classes and id's may not start with a number. In other words start of with a-z Link to comment https://forums.phpfreaks.com/topic/237161-jquery-selecting-last-li-in-the-first-set-of-ul-li/#findComment-1220774 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.