我有这个标记: div class="news-listItem" p class="date"Date: 06.03.2012/p h2a href="#"test aaaaa/a/h2 div class="news-content"Lorem ipsum lorem ipsum Lorem ipsum lorem ipsum Lorem ipsum lorem ipsum Lorem ipsum lorem ipsum Lorem ipsum
<div class="news-listItem"> <p class="date">Date: 06.03.2012</p> <h2><a href="#">test aaaaa</a></h2> <div class="news-content">Lorem ipsum lorem ipsum Lorem ipsum lorem ipsum Lorem ipsum lorem ipsum Lorem ipsum lorem ipsum Lorem ipsum lorem ipsum Lorem ipsum lorem ipsum Lorem ipsum lorem ipsum</div> <a href="#" class="read-more">Read more</a> </div>
我想根据div class =“news-content”获取更多阅读按钮.我的jQuery代码如下所示:
$('.news-content').closest('a.read-more').on('click', function(){ // code here });
但这不起作用.我在页面上有多个帖子,所以我不能做$(‘a.read-more’).
.closest()遍历DOM树.你需要的是.next():$('.news-content').next('a.read-more')