0
How to check classes
How can I check if an HTML has certain class. Im trying with this Var x = ($("#pub").attr("class")).split(); If ("underline" in x) alert("y") But it ain't working, any tips?
2 Answers
+ 3
With vanilla javascript
var x = document.querySelector("#pub");
var hasClass = x.classList.contains("underline");
if (hasClass) {
alert("It has");
}
else {
alert("It seems it doesn't");
}
+ 1
it appear you're using Jquery
this will help you
https://www.w3schools.com/jquery/html_hasclass.asp