Skip to content
Related Articles

Related Articles

Web API | DOMRect width property

View Discussion
Improve Article
Save Article
  • Last Updated : 21 Aug, 2019

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


var recX = DOMRect.width;

Return Type:

Double value

Example: Getting width of the DOMRect object created.

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

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
Recommended Articles
Page :

Start Your Coding Journey Now!