选择最后一个孩子 [英] Selecting the last child
本文介绍了选择最后一个孩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何通过单击链接来得到最后一个孩子的警报.
I was wondering how I'd get an alert of a last child by clicking a link.
<h3 id="comment:5" class="myclass">
这是我走了多远:
$('#lastcomment').click(function() {
alert('Handler for .click() called.');
});
我的目的是通过单击链接跳至最后一条评论.我想第一步应该有个警报.这样我才能看到评论的最后一个子代.
My aim is to jump to the last comment by clicking the link. An alert would be fine for the first step I guess. So that I can see the last child of the comments.
非常感谢您的帮助.
推荐答案
Use the :last
selector or .last()
method:
$("#lastcomment").click(function () {
var lastComment = $("h3[id^=comment]:last");
alert(lastComment.attr("id"));
}
这篇关于选择最后一个孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文