Open In App

Web API DOMRectReadOnly x property

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

The x property in the DOMRectReadOnly API interface is used to represent the x coordinate. It is a read-only property. 

Syntax:

let recX = DOMRect.x;

Return Value: It returns the x coordinate of DOMRectReadOnly API. 

Example: This example uses DOMRect.x property to get the x-coordinate of the DOMRect object. 

HTML




<!DOCTYPE html>
<html>
   
<head>
    <title>
        Web API DOMRectReadOnly x property
    </title>
</head>
 
<body style="text-align:center;">
    <h1 style="color:green;">
        GeeksforGeeks
    </h1>
    <h2>Web API DOMRectReadOnly x property</h2>
    <button onclick="getDOMRect ();">
        Get x-coordinate
    </button>
    <p id='DOMRect'></p>
    <script type="text/javascript">
       
        function getDOMRect() {
            let myDOMRect = new DOMRect(0, 0, 100, 100);
            let recX = myDOMRect.x;
            document.getElementById('DOMRect').innerHTML
                = recX;
        }
    </script>
</body>
 
</html>


Output:

 

Supported Browsers: The browsers supported by DOMRectReadOnly x property are listed below:

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

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads