Reputation: 47
How do I select the last div id blog_comments in this row?
<div id="blog_comments">
<div class="name"><span class="blog_bold">By: </span>SamSambinks</div>
</div>
<div id="blog_comments">
<div class="name"><span class="blog_bold">By: </span>SamSambinks</div>
</div>
<div id="blog_comments">
<div class="name"><span class="blog_bold">By: </span>SamSambinks</div>
</div>
Sounds like a simple question I've tried:
$("#blog_comments:last")
and $("#blog_comments").last
and others but nothing seems to work?
Upvotes: 0
Views: 68
Reputation: 50493
The reason why it's not working is id
needs to be unique.
Make them classes
instead of creating non-unique id's
, having duplicate id's
is actually invalid markup.
<div class="blog_comments">
<div class="name"><span class="blog_bold">By: </span>SamSambinks</div>
</div>
<div class="blog_comments">
<div class="name"><span class="blog_bold">By: </span>SamSambinks</div>
</div>
<div class="blog_comments">
<div class="name"><span class="blog_bold">By: </span>SamSambinks</div>
</div>
Then your selector:
$('.blog_comments').last();
Working Example here
Upvotes: 4
Reputation: 687
You can't have multiple DOM nodes with same id. Try to change id="blog_comments"
to class="blog_comments"
.
Upvotes: 1