The HTML DOM specified property is used for checking if an attribute has been specified or not. It does so by returning true if the attribute has been specified and false otherwise. It will also return true if a given attribute is created but not yet attached to an element.
Syntax
Following is the syntax for the specified property −
attribute.specified
Example
Let us look at the example for the specified property −
<!DOCTYPE html> <html> <body> <p>Click the button find out if the button has an onclick attribute specified.</p> <img id="IMG1" src="https://www.tutorialspoint.com/swing/images/swing-mini-logo.jpg" alt="Learn Swing"> <p> Check if the above image has alt attribute specified by clicking the below button </p> <button onclick="checkAlt()">CHECK</button> <p id="Sample"></p> <script> function checkAlt() { var img = document.getElementById("IMG1"); var s=img.getAttributeNode("alt").specified; if(s==true) document.getElementById("Sample").innerHTML = "The image element has alt attribute specified"; else document.getElementById("Sample").innerHTML = "The image element does not have alt attribute specified"; } </script> </body> </html>
Output
This will produce the following output −
On clicking the CHECK button −