Open In App

Web API DOMRectReadOnly x property

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. 






<!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:

Article Tags :