最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - How can I make a disjunction of element selectors with jQuery? - Stack Overflow

matteradmin5PV0评论

What I need is something like this:

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

I hope I just overlooked this possibility in the jQuery docs.

What I need is something like this:

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

I hope I just overlooked this possibility in the jQuery docs.

Share Improve this question edited Feb 10, 2011 at 14:42 R. Martinho Fernandes 235k72 gold badges441 silver badges516 bronze badges asked Feb 10, 2011 at 14:39 roebroeb 4978 silver badges19 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 5

Just use a ma to separate the selectors:

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

The ma is the CSS syntax for selector grouping.

You can do it with a ma in the selector, or you can use add.

$('element1, element2').mouseover(...);
$('element1').add('element2').mouseover(...);

Sure, just as you can specify it in CSS, just use a ma-separated list:

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

comment list (0)

  1. No comments so far