Web API | DOMRect width property

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

Syntax:

var recX = DOMRect.width;

Return Type:



Double value

Example: Getting width of the DOMRect object created.

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:
Before clicking the button:

After clicked the button:

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

  • Google Chrome
  • Safari 10.1
  • Firefox
  • Opera


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.