Open In App

SVG AElement.href Property

Last Updated : 30 Mar, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

The SVG AElement.href property returns an SVGAnimatedLength object corresponding to the attribute of the given A element

Syntax:

AElement.href

Return value: This property returns SVGAnimatedLength object that can be used to get the href of the AElement.

Example 1: 

html
<!DOCTYPE html>
<html>

<body>
    <svg viewBox="0 0 100 100" 
        xmlns="http://www.w3.org/2000/svg">
        
        <!-- A link around a shape -->
        <a href="https://www.geeksforgeeks.org" id="gfg">
            <circle cx="20" cy="40" r="15" />
        </a>
        
        <script>
            var g = document.getElementById("gfg");
            console.log(g.href);
        </script>
    </svg>
</body>

</html>

Output:

Example 2: 

html
<!DOCTYPE html>
<html>

<body>
    <svg viewBox="0 0 100 100" 
        xmlns="http://www.w3.org/2000/svg">
        
        <!-- A link around a text -->
        <a href="https://www.geeksforgeeks.org" id="gfg">
            <text x="40" y="20" text-anchor="middle">
                &lt;gfg&gt;
            </text>
        </a>
        
        <script>
            var g = document.getElementById("gfg");
            console.log(g.href);
        </script>
    </svg>
</body>

</html>

Output:

Reference: https://developer.mozilla.org/en-US/docs/Web/API/SVGAElement


Similar Reads