Open In App

Web API DOMRect fromRect property

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

In Web API there is a DOMRect Interface which has a property fromRect() which creates a DOMRectReadOnly object which has location and dimensions given. 

Syntax:

let domRect = DOMRectReadOnly.fromRect(DOMRect object)

Return Value:

It returns an instance of DOMRect

Example: Using fromRect. 

HTML




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


Output: 

 

  Supported Browsers:

  • Google Chrome 61
  • Edge 79
  • Safari 10.1
  • Firefox 69
  • Opera 48

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads