jQuery选择类内元素

40
我想要像这样在一个div中选取一个锚点。
<div class="response content">
  Disapproved Bank Mandiri<br><br>
  <p>
    <a class="showlist" href="#">Back to list?</a>
  </p>
</div>

有什么jQuery代码可以实现这个功能?


8
在提问之前,你应该先阅读jQuery中的选择器(http://api.jquery.com/category/selectors/)。请确保翻译内容通俗易懂且不改变原意。 - Reigel Gallarde
4个回答

64
任何带有“response”和“content”类的div中的锚点:
$('.response.content a')

或者只有 class 为 "showlist" 的锚点:

$('.response.content a.showlist')

11

如果您需要在 DIV 上同时使用两个类:

$("div.response.content a.showlist");

如果不是这样,

$("div.response a.showlist");

要了解有关jQuery选择器的基本用法,请访问http://api.jquery.com/category/selectors/


4

你可以使用jQuery .find() 解决这个问题。

以下是使用find()方法选择所有带有"class"属性值为"response content"的div元素的示例。

jQuery('.response.content').find('a');

这篇文章涉及选择器 vs. .find()这个话题,对编程有帮助。


0

你可以使用:

$('.response').find('a');

或者

$('.response').find('.showlist');

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接