Reputation:
<div class="testClass">
<div>
<select name="specialName123">
</select>
</div>
</div>
<div class="testClass">
<div>
<span id="someSpan">
<select name="specialName123">
</select>
</span>
</div>
</div>
How do I select the two above divs on my page based on the fact that they have the class "testClass" and have a select that has "123" in it's name?
I understand I can find all selects like so $('select[name*="123"]')
, and I can use $(".testClass")
to select the appropriate divs. But how do I put these together in the way I need to?
Upvotes: 3
Views: 1067
Reputation: 144689
You can use closest
method:
$('select[name*="123"]').closest('.testClass')
or:
$('.testClass').has("select[name*=123]")
Upvotes: 2
Reputation: 4774
You can also use the find
method to get all the descendants of testClass
, which you can then filter by a selector:
$('.testClass').find('select[name*="123"]');
Upvotes: 0
Reputation: 14863
Why not:
$('.testClass select[name*="123"]')
It maches any children of testclass (any depth) that is a select-box with name containing 123.
Upvotes: 1