Reputation: 3769
I would like to check for
#dialogOrder
and
.menu-mask
Is the following valid and is there an even easier shortcut ?
$("#dialogOrder").$(".menu-mask")
Update
I just realized I also need to select the element only if it is on a form with the class of menu. Sorry that this was not part of the original question. I hope someone can help me.
Upvotes: 1
Views: 76
Reputation: 164723
If you mean you want to find an element with both ID dialogOrder
and class menu-mask
, simply use
jQuery("#dialogOrder.menu-mask")
If you want to know if this element exists in your document, try
if (jQuery("#dialogOrder.menu-mask").length > 0) {
// element exists
}
Of course, adding the class selector is redundant as there should only be at most one element with any given ID attribute.
To answer your comment, if you mean you want to find dialogOrder
in
<form class="menu">
<div id="dialogOrder">...</div>
</form>
You can use several methods
$("form.menu").find("#dialogOrder")
or
$("form.menu #dialogOrder")
Upvotes: 2
Reputation: 179046
You chain the selectors:
$('#dialogOrder.menu-mask')
If you need to use a pre-existing selector, you can use the filter
method:
$('.menu-mask').doStuff().filter('#dialogOrder').doMoreStuff();
Upvotes: 1
Reputation: 1179
If you are looking for a tag that is both #dialogOrder
AND .menu-mask
, then you should use:
$("#dialogOrder.menu-mask")
Upvotes: 3