The Element.hasAttribute() method returns a Boolean value indicating whether the specified element has the specified attribute or not.
hasAttribute(name)nameis a string representing the name of the attribute.
A boolean.
const foo = document.getElementById("foo");
if (foo.hasAttribute("bar")) {
// do something
}