How can I make a disjunction of element selectors using jQuery?

I need something like this:

$('element1 or element2').mouseover(function()
{
   $('element3').show(effects,blah);
});

Hope I just missed this opportunity in jQuery docs.

+3
source share
3 answers

Just use a comma to separate the selectors:

$('element1, element2').mouseover(function()
{
   $('element3').show(effects,blah);
});

Comma is CSS syntax for selector grouping .

+5
source

You can do this with a comma in the selector , or you can use add.

$('element1, element2').mouseover(...);
$('element1').add('element2').mouseover(...);
+4
source

Of course, just as you can specify it in CSS, just use a comma separated list:

$('.element1, .element2').mouseover(function() { 
    $('element3').show(effects,blah); 
});
0
source

Source: https://habr.com/ru/post/1791232/


All Articles