I have two divs with id's: #addNew_tab
and #sendCom_tab
.
I'd like clicking on either of these to trigger the same jQuery click()
function.
I was thinking something like:
$("#addNew_tab", "#sendCom_tab").click(function(){
//do stuff
});
but that doesn't work.
The descendant combinator — typically represented by a single space (" ") character — combines two selectors such that elements matched by the second selector are selected if they have an ancestor (parent, parent's parent, parent's parent's parent, etc.) element matching the first selector.
You can specify any number of selectors to combine into a single result. This multiple expression combinator is an efficient way to select disparate elements. The order of the DOM elements in the returned jQuery object may not be identical, as they will be in document order.
So far we have covered only three standard jQuery Selectors. For a complete detail of all these jQuery selectors, you can go to through jQuery Selectors Reference.
jQuery selector: jQuery selectors are used to selecting the HTML element(s) and allow you to manipulate the HTML element(s) in a way we want. It selects the HTML elements on a variable parameter such as their name, classes, id, types, attributes, attribute values, etc.
$("#addNew_tab, #sendCom_tab").click(function(){
//do stuff
});
Changed from:
$("#addNew_tab", "#sendCom_tab")
To:
$("#addNew_tab, #sendCom_tab")
comma inside the selector("a, b")
means the first plus the second; Just like with CSS selectors
(Well, it's a CSS selector...)
jQuery(selector)
Description: Accepts a string containing a CSS selector which is then used to match a set of elements.
It's equal to:
$("#addNew_tab").add("#sendCom_tab")...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With