What is jQuery has id equivalent of the following statement?
$('#mydiv').hasClass('foo')
so you could give a class name and check that it contains a supplied id.
something like:
$('.mydiv').hasId('foo')
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.
You can bake that logic into the selector by combining multiple selectors. For instance, we could target all elements with a given id, that also have a particular class:
This should look similar to something you’d write in CSS. Note that it won’t apply to all
#fooelements (though there should only be one), and it won’t apply to all.barelements (though there may be many). It will only reference elements that qualify on both attributes.jQuery also has a great
.ismethod that lets your determine whether an element has certain qualities. You can test a jQuery collection against a string selector, an HTML Element, or another jQuery object. In this case, we’ll just check it against a string selector: