Open In App

Web API DOMRect right property

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

In Web API there is a DOMRect Interface that has a property right that gives us the right of the DOMRect object. It returns x + width coordinate value or if the width is negative then it returns x

Syntax:

let recX = DOMRect.right;

Return Type:

Double value

Example 1: When the width is positive 

HTML




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


Output: 

 

Example 2: When the width is negative 

HTML




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


Output: 

 

Supported Browsers: The browsers supported by DOMRect right property are listed below:

  • Google Chrome
  • Safari 10.1
  • Firefox
  • Opera


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads