jQuery selectors: logical OR

2020-03-01 03:17发布

I can't seem to see the forest for the trees right now (Looked at the api docs already).
It has to do with jQuery selectors: What I'm trying to do is to select all elements that have class subtitle or headsection. Something like this: $('.headsection || .subtitle');

To be more specific: I want to use this selector with the function nextUntil.

$content = $some_elements.eq(0).nextUntil('.headsection || subtitle');

As far as I know || is not available in jQuery's selectors. So what's the best way to accomplish that?

Thanks for your help!

6条回答
smile是对你的礼貌
2楼-- · 2020-03-01 03:33

It's the same as in CSS selectors:

$('.headsection, .subtitle');
查看更多
姐就是有狂的资本
3楼-- · 2020-03-01 03:35

What about: $some_elements.eq(0).nextUntil('.headsection, .subtitle');

Works for me at least. Read about multiple selectors.

查看更多
家丑人穷心不美
4楼-- · 2020-03-01 03:35

jQuery uses the CSS selector syntax, so if you know that, just put the same selectors into jQuery and bob's your metaphorical uncle. jQuery uses the sizzle selector engine which supports virtually all CSS3 selectors :)

As everyone has already said - the way to do it is this: $content = $some_elements.eq(0).nextUntil('.headsection, subtitle');

查看更多
来,给爷笑一个
5楼-- · 2020-03-01 03:39

You don't really need a logical OR as such, $('.headsection, .subtitle') should do the job.

查看更多
爷、活的狠高调
6楼-- · 2020-03-01 03:44

Would the multiple selector work for what you're doing? Api doc is here.

查看更多
ら.Afraid
7楼-- · 2020-03-01 03:45

Just separate them with a comma:

$content = $some_elements.eq(0).nextUntil('.headsection, subtitle');
查看更多
登录 后发表回答