Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
215 views
in Technique[技术] by (71.8m points)

javascript - 使用jQuery选择多个类(Selecting multiple classes with jQuery)

I've had a good look and can't seem to find out how to select all elements matching certain classes in one jQuery selector statement such as this:(我看起来很好看,似乎无法找到如何在一个jQuery选择器语句中选择匹配某些类的所有元素,如下所示:)

$('.myClass', '.myOtherClass').removeClass('theclass'); Any ideas on how to achieve this?(关于如何实现这一点的任何想法?) The only other option is to do(唯一的另一种选择是做) $('.myClass').removeClass('theclass'); $('.myOtherClass').removeClass('theclass'); But I'm doing this with quite a few classes, so it requires much code.(但我正在使用相当多的类,所以它需要很多代码。)   ask by Kezzer translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This should work:(这应该工作:)

$('.myClass, .myOtherClass').removeClass('theclass'); You must add the multiple selectors all in the first argument to $(), otherwise you are giving jQuery a context in which to search, which is not what you want.(您必须在$()的第一个参数中添加多个选择器,否则您将为jQuery提供要搜索的上下文,这不是您想要的。) It's the same as you would do in CSS.(它和你在CSS中做的一样。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...