Guest User

Untitled

a guest
Aug 15th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. jQuery - How to check if element has any of these classes
  2. <div id="test" class="a1 a2 a5"></div>
  3.  
  4. $("#test").is(".a1,.a2,.a3,.a4,.a5")
  5.  
  6. if($('#test').filter('.a1, .a2, .a3').length)
  7. {
  8. //magic happens
  9. }
  10.  
  11. var test = $('#test');
  12. if(test.hasClass('a1') || test.hasClass('a2') || test.hasClass('a3') ...) {
  13. ...
  14. }
  15.  
  16. if ( $("#test").hasClass("a1") or $("#test").hasClass("a2") ...) { }
  17.  
  18. if ($("#test").hasClass("a1") || $("#test").hasClass("a2") || $("#test").hasClass("a3") || $("#test").hasClass("a4") || $("#test").hasClass("a5")) {
  19.  
  20. // Do something
  21.  
  22. }
Add Comment
Please, Sign In to add comment