Skip to content
Related Articles

Related Articles

HTML | DOM Object name Property

View Discussion
Improve Article
Save Article
Like Article
  • Difficulty Level : Basic
  • Last Updated : 16 Aug, 2021

The HTML | DOM Object name Property is used to set or return the value of a name attribute of an <object> element. The name attribute is used to specify the name of the embedded file.
Syntax: 
 

  • It returns the name property 
     
objObject.name
  • It is used to set the name property. 
     
objObject.name = name

Property Values: It contains the value i.e name which is used to specify the name of the embedded file.
Return Value: It returns a string value which represents the name of an <object> element.
Example-1: This Example returns a name Property. 
 

html




<!DOCTYPE html>
<html>
 
<body>
    <center>
        <object id="myobject"
                width="400"
                height="100"
                name="myGeeks"
                data=
      </object>
        <h2>
          DOM Object name Property
      </h2>
         
<p>
          Click the button to get
          the name of the embedded file.
      </p>
 
 
        <button onclick="Geeks()">
            Click it
        </button>
 
        <p id="gfg"
           style="color:green;
                  font-size:25px;">
      </p>
 
    </center>
    <script>
        function Geeks() {
 
            // Accessing Object element.
            var x =
                document.getElementById(
                    "myobject").name;
 
            document.getElementById(
                "gfg").innerHTML = x;
        }
    </script>
 
</body>
 
</html>

Output: 
Before Clicking On Button: 
 

After Clicking On Button: 
 

Example-2: This Example sets the name Property. 
 

html




<!DOCTYPE html>
<html>
 
<body>
    <center>
        <object id="myobject"
                width="400"
                height="100"
                name="myGeeks"
                data=
      </object>
        <h2>
          DOM Object name Property
      </h2>
         
<p>
          Click the button to change
          the name of the embedded file.
      </p>
 
 
        <button onclick="Geeks()">
            Click it
        </button>
 
        <p id="gfg"
           style="color:green;
                  font-size:25px;">
      </p>
 
    </center>
    <script>
        function Geeks() {
 
            // Accessing Object element.
            var x =
                document.getElementById(
                    "myobject").name = "Obj1";
 
            document.getElementById(
                "gfg").innerHTML =
              "The value of the name attribute"+
              " was changed to " + x;
        }
    </script>
 
</body>
 
</html>

Output: 
Before Clicking On Button: 
 

After Clicking On Button: 
 

Supported Browsers: 
 

  • Google Chrome 
     
  • Mozilla Firefox 
     
  • Edge 
     
  • Opera 
     
  • Safari 
     

 


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!