Skip to content
Related Articles

Related Articles

Improve Article

SVG RectElement.x Property

  • Last Updated : 30 Oct, 2020

The SVG RectElement.x property returns an SVGAnimatedLength corresponding to the attribute of the given rectangle element

Syntax:

RectElement.x

Return Values: This property returns SVGAnimatedLength object that can be used get the x-axis of the rect element

Example 1: 

HTML




<!DOCTYPE html>
<html>
  
<body>
    <svg width="350" height="150" 
        xmlns="http://www.w3.org/2000/svg">
          
        <rect width="100" height='100' 
            fill="green" id="gfg" x=20 y=20 />
              
        <script>
            var g = document.getElementById("gfg");
            console.log(g.x);
        </script>
    </svg>
</body>
  
</html>

Output:



Example 2: 

HTML




<!DOCTYPE html>
<html>
  
<body>
    <svg width="350" height="150" 
        xmlns="http://www.w3.org/2000/svg">
          
        <rect width="100" height='100' 
            fill="green" id="gfg" x=30 y=20 />
              
        <script>
            var g = document.getElementById("gfg");
            console.log(g.x)
        </script>
    </svg>
</body>
  
</html>

Output:

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 :