Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

HTML | DOM Object width Property

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The DOM Object width Property in HTML DOM is used to set or return the width of the Object. The width attribute is used to specify the width of an Object.

Syntax: 

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

Property Values: It contains the value i.e pixel which specifies the width of the object in terms of the pixel.

Return Value: It returns a numeric value that represents the width of the object in terms of the pixel.

Example-1: This Example returns a width Property.  

HTML




<!DOCTYPE html>
<html>
<body>
    <center>
        <object id="myobject"
                width="400"
                data=
        </object>
        <h2>
          DOM Object width Property
          </h2>
         
<p>
          Click the button to get
          the width 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() {
 
            // return object width property
            var x =
                document.getElementById(
                    "myobject").width;
 
            document.getElementById(
                "gfg").innerHTML = x;
        }
    </script>
</body>
</html>

Output: 

Before Clicking On Button: 

After Clicking On Button:  

Example-2: This Example sets the width Property.  

HTML




<!DOCTYPE html>
<html>
<body>
    <center>
        <object id="myobject"
                width="400"
                data=
        </object>
        <h2>
          DOM Object width Property
          </h2>
         
<p>
          Click the button to get
          the width 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() {
 
            // set object width property
            var x =
                document.getElementById(
                    "myobject").width = "500";
 
            document.getElementById(
                "gfg").innerHTML =
              "The value of the width "+
              "attribute was changed to " + x;
        }
    </script>
</body>
</html>

Output: 

Before Clicking On Button: 

After Clicking On Button:  

Supported Browsers:  

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

My Personal Notes arrow_drop_up
Last Updated : 25 Aug, 2022
Like Article
Save Article
Similar Reads
Related Tutorials