HTML DOM name Property

HTMLWeb DevelopmentFront End Technology

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

elementAttribute.name

Let us see an example of HTML DOM name property −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<title>HTML DOM name</title>
<style>
   * {
      padding: 2px;
      margin:5px;
   }
   form {
      width:70%;
      margin: 0 auto;
      text-align: center;
   }
   input[type="button"] {
      border-radius: 10px;
   }
</style>
</head>
<body>
   <form>
      <fieldset>
         <legend>HTML-DOM-name</legend>
         <img src="https://www.tutorialspoint.com/data_communication_computer_network/images/dcn-   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()">
      </fieldset>
   </form>
<script>
   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';
   }
</script>
</body>
</html>

Output

Before clicking ‘Get Answer’ button −

After clicking ‘Get Answer’ button −

raja
Published on 25-Oct-2019 07:26:33
Advertisements