Skip to content Skip to sidebar Skip to footer

Jquery Concatenation Of Selectors Without Creating A New Instance?

Is is possible to concatenate two jQuery selectors without creating a new selector in the process? An example would be as follows:

Solution 1:

You can use multiple selectors in jQuery:

$('.a, .b')

The above selector will select all elements that have the class .a and/or .b

Solution 2:

You can use internal hack method push:

a.push.apply(a, b.get());  // it accepts only native DOM elements

But I wouldn't suggest you to use it, since it is not documented and provided for internal use only. Instead use simple: a = a.add(b).

REF:https://stackoverflow.com/a/14345461/1249581

Solution 3:

You can use multiple selectors in a jQuery string simply by comma-separating them, like so:

$('.a, .b')

Post a Comment for "Jquery Concatenation Of Selectors Without Creating A New Instance?"