Web DOMRect API | DOMRect() Constructor

The DOMRect() constructor in DOMRect API is used to create DOMRect object which represents a rectangle.

Syntax:

var myDOMRect = new DOMRect(x, y, width, height);

Parameters: This constructor contains four parameters as mentioned above and described below:

  • x: It sets the x-coordinate of the rectangle.
  • y: It sets the y-coordinate of the rectangle.
  • width: It sets the width of the rectangle.
  • height: It sets the height of the rectangle.

Example: This example creates a DOMRect object with given parameters.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html
  
<head>
    <title>
        Web API | DOMRect() Constructor
    </title>
</head>
  
<body style="text-align:center;">
      
    <h1 style="color:green;"
        GeeksForGeeks 
    </h1
                  
    <h2>Web API | DOMRect() Constructor</h2>
      
    <button onclick="getDOMRect ();">
        Get DOMRect object
    </button>
      
    <p id='DOMRect'></p>
  
    <script type="text/javascript">
        function getDOMRect () {
            var myDOMRect = new DOMRect(0, 0, 100, 100);
            console.log(myDOMRect);
        }
    </script
</body>
  
</html>

chevron_right


Output:

  • Before Click the button:
  • After Click the Button console view:

Supported Browsers: The browsers supported by DOMRect() constructor are listed below:

  • Google Chrome
  • Firefox
  • Opera
  • Safari 10.1


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.