Open In App

Web DOMRect API DOMRect() Constructor

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

Syntax:



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

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

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






<!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() {
           let myDOMRect = new DOMRect(0, 0, 100, 100);
            console.log(myDOMRect);
        }
    </script>
</body>
 
</html>

Output:

 

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

Article Tags :