The Wayback Machine - https://web.archive.org/web/20240622103927/https://www.geeksforgeeks.org/svg-element-innerhtml-property/
Open In App

SVG Element.innerHTML Property

Last Updated : 30 Mar, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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

Syntax:

const content = element.innerHTML

Return value: This property returns innerHTML of the element.

Example 1: 




<!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.innerHTML);
        </script>
    </svg>
</body>
  
</html>


Output:

Example 2: 




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


Output:



Previous Article
Next Article

Similar Reads

HTML DOM innerHTML Property
The DOM innerHTML property is used to set or return the HTML content of an element. Syntax: It returns the innerHTML Property. Object.innerHTMLIt is used to set the innerHTML property. Object.innerHTML = valueWhere, value: It represents the text content of the HTML element.Return Value: This property returns a string that represents the HTML conten
2 min read
How to replace innerHTML of a div using jQuery?
For replacing innerHTML of a div with jquery, html() function is used. Syntax: $(selector).html() Example: &lt;!DOCTYPE html&gt; &lt;html lang=&quot;en&quot;&gt; &lt;head&gt; &lt;meta charset=&quot;UTF-8&quot;&gt; &lt;title&gt; changing-innerhtml-using-jquery &lt;/title&gt; &lt;link href= &quot;https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css
1 min read
Difference between innerText and innerHTML
innerText and innerHTML are both properties of JavaScript. However, there are differences in which the text is handled. Let us check the syntax of the two and then take an example to look at the differences. Syntax: Let us assume that we have a JavaScript variable called x. let x = document.getElementById('test');innerTextx.innerTextinnerHTMLx.inne
1 min read
How to add innerHTML to print page?
Here is the task to add innerHTML to the print page. Here we are going to change the present content inside the &lt;body&gt; element and sets them with the new specified content using document.body with the help of .innerHTML which specify the content to be printed. We’re going to discuss a few methods. Example 1: In this example, the specified con
2 min read
What is the Disadvantage of using innerHTML in JavaScript ?
The innerHTML property is a part of the Document Object Model (DOM) that is used to set or return the HTML content of an element. Where the return value represents the text content of the HTML element. It allows JavaScript code to manipulate a website being displayed. More specifically, it sets or returns the HTML content (the inner HTML) of an ele
3 min read
Difference between textContent and innerHTML
The textContent and innerHTML are properties of JavaScript. However, there are differences in the way the specified text is handled in JavaScript. Let us take a look at the syntax of both of these properties. Syntax: Let elem be a JavaScript variable that holds an element that is selected from the page. let elem = document.getElementById('test-btn'
2 min read
How to use innerHtml in React JS ?
React.js provides a easy way of handling UI updates. However, sometimes you need to inject HTML directly into your components. PrerequisitesIntroduction to ReactReact ComponentsReact HooksNPM or NPXIn this article, we are going to learn how can we use InnerHTML in React JS. We can add HTML into ReactJS by using the 'dangerouslySetInnerHTML' propert
2 min read
Why is it Better to use textContent instead of innerHTML ?
Using textContent instead of innerHTML is generally considered better practice when dealing with text content in the context of the Document Object Model (DOM). Here are a few reasons why textContent is often preferred: Security: Using textContent helps in reducing the risk of security vulnerabilities such as Cross-Site Scripting (XSS). When you us
1 min read
JavaScript innerHTML
The innerHTML property in JavScript is used to append the dynamic HTML or text content to an element using JavaScript. It is designed to add dynamic HTML, but developers also use it to add text content as well. It can be directly used with the element by selecting it using DOM manipulation. Syntax:selctedHTMLElement.innerHTML = "contentToAppend";Ex
2 min read
How to use innerHTML in JavaScript ?
The innerHTML property in JavaScript allows you to get or set the HTML content of an element as a string. Syntax ForGetting HTML content of an element:let element = document.getElementById("myElementId"); let htmlContent = element.innerHTML;Setting HTML content of an element:let element = document.getElementById("myElementId"); element.innerHTML =
2 min read
three90RightbarBannerImg