Skip to content
Related Articles

Related Articles

Improve Article
SVG Element.id Property
  • Last Updated : 03 Nov, 2020

The SVG Element.id property returns the id of the given element.

Syntax:

var idStr = element.id; // Get the id

Return value: This property returns the id of the element.

Example 1: 

HTML




<!DOCTYPE html> 
<html
  
<body
    <svg width="350" height="350" 
        xmlns="http://www.w3.org/2000/svg">
        <a href="https://www.geeksforgeeks.org" id="gfg">
            <circle cx='100' cy='100' r="80"></circle>
        </a>
        <script>
            var g = document.getElementById('gfg');
            console.log(g.id)
        </script>
    </svg>
</body
  
</html>

Output:



Example 2: 

HTML




<!DOCTYPE html> 
<html
  
<body
    <svg width="350" height="100" 
        xmlns="http://www.w3.org/2000/svg">
        <a href="https://www.geeksforgeeks.org" id="gfg">
            <text x='100' y='50' font-size="50px">GfG</text>
        </a>
        <script>
            var g = document.getElementById('gfg');
            console.log(g.id)
        </script>
    </svg>
</body
  
</html>

Output:




My Personal Notes arrow_drop_up
Recommended Articles
Page :