What is the jQuery selector for selecting anchor elements with a particular class in a particular div

北战南征 提交于 2019-12-07 10:20:36

问题


I have some code like this and I want to select every <a> tag with the class status in the div foo

<div id="foo">
...
<a class = "status"> ... </a>
...
</div>

回答1:


You can do this $('#foo').find('.status')




回答2:


The selector would be:

$("#foo a.status");



回答3:


Try this and read this:

$("#foo a.status")

Good luck!




回答4:


This works.

$("#foo").find("a.status")



回答5:


Try this:

$('div#foo a.status')

The docs are here




回答6:


try with

$('div#foo > a.status')

it selects the anchors which are DIRECT children of div #foo




回答7:


jQuery('#foo')     //select elm with id foo
.find('a.status')  //find anchor with class



回答8:


There is no such thing as a "jQuery selector", what you mean is :

either CSS selector :

In that case the answer is div#foo a.status or also div#foo > a.status (depending if there are intermediate containers)

or jQuery functions :

In that case there are several ways to do it :

  • $('div#foo a.status')
  • $('div#foo > a.status')
  • $('div#foo').find('a.status')
  • $('div#foo').children('a.status')


来源:https://stackoverflow.com/questions/5062989/what-is-the-jquery-selector-for-selecting-anchor-elements-with-a-particular-clas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!