Open In App

Web API DOMRect width property

Last Updated : 15 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In Web API there is a DOMRectReadOnly Interface which has a property width that gives us the width of the DOMRect object. 

Syntax:

let recX = DOMRect.width;

Return Type:

Double value

Example: Getting the width of the DOMRect object created. 

HTML




<!DOCTYPE html>
<html>
   
<head>
    <title>
        DOMRect width property
    </title>
</head>
 
<body>
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>
    <h2>DOMRect width property</h2>
    <button onclick="getDOMRect ();">
        Get width
    </button>
    <p id='DOMRect'></p>
 
    <script type="text/javascript">
        function getDOMRect() {
            let myDOMRect = new DOMRect(
                0, 0, 100, 100);
            let recwidth = myDOMRect.width;
 
            document.getElementById(
                'DOMRect').innerHTML = recwidth;
        }
    </script>
</body>
 
</html>


Output:

 

Supported Browsers: The browsers supported by the DOMRect width property are listed below:

  • Google Chrome
  • Safari 10.1
  • Firefox
  • Opera

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads