I am trying to check if a selector has certain sets of classes.
.hasClass () can only check if the selector has one class. And the .is () selector can search for several classes, but returns true if the selector has at least one of the classes.
But I could not find a way to check if the selector has both classes, and only if it has both classes. Act
Any pointers?
You can simply name the class names:
.foo.bar.bar
This selector matches any element that has all the classes foo, bar, and baz.
The is () function should work for you.
I think $.is('.class1.class2') will do what you want. For example, $('#foo').is('.a.b') returns true for the next div , but $('#foo').is('.a.c') returns false:
$.is('.class1.class2')
$('#foo').is('.a.b')
div
$('#foo').is('.a.c')
<div id="foo" class="ab"></div>
Isn't that what you are looking for?
does $('div.class1.class2') not do what you need (i.e. find any div with class1 and class2)
$('div.class1.class2')
You can simply do:
var $blah = $("blah"); if($blah.hasClass("test") && $blah.hasClass("othertest")){ // something }
... or use the selector
$(".test.othertest");
Source: https://habr.com/ru/post/1307353/More articles:How to automatically insert class notation using eclipse templates? - javaManage multiple .NET languages ββin a web application - .netVisual Studio: The Best Way to Use Multiple Programming Languages ββfor a Single Application - .netCan I configure Hudson to prevent certain users from accessing certain users? - hudsonhttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1307352/making-gwt-rpc-calls-to-an-external-service-for-which-you-dont-have-code&usg=ALkJrhgseKxiYEQs0mZm1WwS_XVCvqgdLASilverlight 3 child resource property is not updated - data-bindingHow can I get and use custom TZ settings from my .bashrc in a Perl CGI script? - timezoneWPF TreeView bind to hide / show expand / collapse icon - data-bindingC ++ Code Analysis - how to add a custom dictionary? - c ++PHP calls a function like PostgreSQL? - sqlAll Articles