In jQuery, you can select multiple elements by separate it with a comma “,” symbol.
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. An alternative to this combinator is the .
Two selectors: visible and: hidden are also available in JQuery.
The second argument (".demo"
in your example) is the context, basically your selector is restricted to match only descendants of a determined context:
$(expr, context)
Is just equivalent to use the find
method:
$(context).find(expr)
Give a look to the documentation of the jQuery function:
Selector Context
By default, selectors perform their searches within the DOM starting at the document root. However, an alternate context can be given for the search by using the optional second parameter to the
$()
function. For example, if within a callback function we wish to do a search for an element, we can restrict that search:
$('div.foo').click(function() {
$('span', this).addClass('bar');
// it will find span elements that are
// descendants of the clicked element (this)
});
Also notice that the selector you post "button, input:submit, a"
, is called Multiple Selector, and there you can specify any number of selectors to combine into a single result, just by separating them by a comma.
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