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 −

obj.name

Following is the syntax to return the object name property −

obj.name = name

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

Example

 Live Demo

<!DOCTYPE html>
<html>
<body>
<object id="obj1" width="570" height="350" data="https://www.tutorialspoint.com/flex/samples/CSSApplication.swf" name="obj"></object>
<button onclick="display()">Change the object name</button>
<p id="demo"></p>
<script>
   function display() {
      document.getElementById("obj1").name = "obj2";
      document.getElementById("demo").innerHTML = "Name updated to obj2";
   }
</script>
</body>
</html>

Output

Now, click the button to update the object name −

Updated on: 30-Jul-2019

100 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements