Skip to content
Related Articles

Related Articles

Web API | DOMRectReadOnly x property
  • Last Updated : 08 Aug, 2019
GeeksforGeeks - Summer Carnival Banner

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

Syntax:

var 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 () {
            var myDOMRect = new DOMRect(0, 0, 100, 100);
            var recX = myDOMRect.x;
  
            document.getElementById('DOMRect').innerHTML
                    = recX;
        }
    </script
<body>
      
</html>

Output:

  • Before Click the Button:
  • After Click the Button:

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

  • Google Chrome
  • Firefox
  • Safari 10.1
  • Opera

full-stack-img




My Personal Notes arrow_drop_up
Recommended Articles
Page :