HTML DOM Object name Property

The HTML DOM Object name property sets or returns the value of the name attribute. However, the name attribute only sets the name.

Following is the syntax to set the object name property −

Following is the syntax to return the object name property − = name

Let us now see an example to implement the DOM Object name property −


 Live Demo

<!DOCTYPE html>
<object id="obj1" width="570" height="350" data="" name="obj"></object>
<button onclick="display()">Change the object name</button>
<p id="demo"></p>
   function display() {
      document.getElementById("obj1").name = "obj2";
      document.getElementById("demo").innerHTML = "Name updated to obj2";


Now, click the button to update the object name −