I have a simple if statement:
if ($('html').hasClass('m320')) { // do stuff }
This works as expected. However, I want to add more classes in the if statement to check if any of the classes are present in the <html> . I need this so that not all of them, but just the presence of at least one class, but it can be more.
My use case is that I have classes (e.g. m320 , m768 ) added for different viewport widths, so I only want to execute a specific jQuery if it's a specific width (class).
Here is what I have tried so far:
one.
if ($('html').hasClass('m320', 'm768')) { // do stuff }
2.
if ($('html').hasClass('m320')) || ($('html').hasClass('m768')) { // do stuff }
3.
if ($('html').hasClass(['m320', 'm768'])) { // do stuff }
None of this seems to work. Not sure what I'm doing wrong, but most likely my syntax or structure.
javascript jquery syntax logic
Danny Englander May 11 '12 at 21:55 2012-05-11 21:55
source share