开发者

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

What I need is something like this:

$('element1 or element2').mouseover(function()
{
   $('element3').show(e开发者_JS百科ffects,blah);
});

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


Just use a comma to separate the selectors:

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

The comma is the CSS syntax for selector grouping.


You can do it with a comma 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 comma-separated list:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜