Skip to content
Related Articles

Related Articles

Improve Article

Web API | DOMRect fromRect property

  • Last Updated : 21 Aug, 2019

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


var domRect = DOMRectReadOnly.fromRect(DOMRect object)

Return Value:

It returns an instance of DOMRect

Example: Using fromRect.

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

Before click the button:

After clicked the button:

Supported Browsers:

  • Google Chrome
  • Safari 10.1
  • Firefox
  • Opera

Attention reader! Don’t stop learning now. Get hold of all the important Comcompetitivepetitve Programming concepts with the Web Design for Beginners | HTML  course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :