The specified
property returns true if the attribute is specified.
specified |
Yes | Yes | Yes | Yes | Yes |
var v = attribute.specified
A Boolean, true|false, to tell if an attribute has been set.
The following code shows how to find out if an attribute has been set or not.
<!DOCTYPE html>
<html>
<body>
<!-- w w w . j a v a2 s . com-->
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var btn = document.getElementsByTagName("BUTTON")[0];
var x = document.getElementById("demo");
x.innerHTML = btn.getAttributeNode("onclick").specified;
}
</script>
</body>
</html>
The code above is rendered as follows: