Is there a way to check if two elements have the same class name? My code looks like this…
<body class="foo bar cats">
<a href="#" class="foo">Link</a>
<a href="#" class="puppies">Link</a>
What I want to do is add another class to the foo link if it matches a class in the body. How would I check if one of the classes in my links matches a class in the body with jQuery?
I’d suggest:
JS Fiddle demo.
Edited to try and account for Internet Explorer’s inability to understand/use/implement
.classList:JS Fiddle demo.
Edited because it appears my previous attempt, to account for IE, failed. Sigh. Still! This approach should work, albeit I can’t test it, as I’m without both IE and Windows:
JS Fiddle demo.
References:
classList.hasClass().