HTML DOM name Property

The HTML DOM name property returns a string corresponding to the name of the attribute of an element.

Following is the syntax −

Returning string value

Let us see an example of HTML DOM name property −

 Live Demo

<!DOCTYPE html>
<title>HTML DOM name</title>
   * {
      padding: 2px;
   form {
      margin: 0 auto;
      text-align: center;
   input[type="button"] {
      border-radius: 10px;
         <img src="   mini-logo.jpg">
         <div id="divDisplay">What attribute in img element is used as a source path?</div>
         <input type="button" value="Get Answer" onclick="getAnswers()">
   var divDisplay = document.getElementById("divDisplay");
   function getAnswers() {
      var ans = document.getElementsByTagName('img')[0].attributes[0].name;
      divDisplay.textContent = 'A \"'+ans+'\" attribute is used as a source path in img element';


Before clicking ‘Get Answer’ button −

After clicking ‘Get Answer’ button −