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>
You can do this $('#foo').find('.status')
The selector would be:
$("#foo a.status");
This works.
$("#foo").find("a.status")
try with
$('div#foo > a.status')
it selects the anchors which are DIRECT children of div #foo
jQuery('#foo') //select elm with id foo
.find('a.status') //find anchor with class
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