Say I have:
<div class="outer">
<div class="foo bar"></div>
</div>
How can I check to see if $('.outer') has a div with a class named “bar” within it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use the
:hasselector.jsFiddle.
This will select all elements with a class of
barwith aouterancestor.If you have a reference to a collection selected with
$('.outer'), you can drop ones which don’t have the child element withfilter()and:has.jsFiddle.
If you have a reference to a
barand want to know if it has a.outerancestor, you could do…jsFiddle.