hasAttribute
<!DOCTYPE HTML>
<html>
<head>
<title>Example</title>
</head>
<body>
<p id="textblock" class="Survey numbers">
This is a test.
</p>
<pre id="results"></pre>
<script>
var elem = document.getElementById("textblock");
document.writeln("lang attribute: " + elem.hasAttribute("lang"));
elem.setAttribute("lang", "en-US");
document.writeln("Attr value is : " + elem.getAttribute("lang"));
elem.setAttribute("lang", "en-UK");
document.writeln("Value is now: " + elem.getAttribute("lang"));
</script>
</body>
</html>
Home
JavaScript Book
DOM
JavaScript Book
DOM
HTMLElement:
- The HTMLElement Members
- element tag name, id, direction, language, hidden disabled information
- addEventListener
- appendChild
- attributes returns a collection containing all of the attributes
- classList
- className
- cloneNode
- createElement
- createTextNode
- dataset
- getAttribute
- getElementsByTagName
- hasAttribute
- innerHTML
- insertAdjacentHTML
- insertBefore
- isSameNode
- outerHTML
- onmouseout
- onmouseover
- querySelectorAll
- removeEventListener