[ACCEPTED]-get the ID of last DIV inside a DIV using jQuery-html
Accepted answer
You can try this:
jQuery Code
$(document).ready(function(){
$('#container').children().last().attr('id');
});
0
Try this:
var id = $('#container div:last').attr('id')
0
Well you can do this:
$("#container div").last().attr("id")
Or if you only want 5 to include divs that are direct children 4 of #container
(assuming your real-world code has more 3 elements and might have divs inside the 2 divs) change the above selector to "#container > div"
.
But 1 note that there's no one "correct" way.
You can use the .last()
method which will help 2 you to match the last element.
You can then 1 get the id
$('#container div').last().attr('id');
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.