akm
akm

Reputation: 465

Change text svg JavaScript

How to change text assigned ID with "txtcircle" in JavaScript? My object is below:

<svg  width="100" height="100" id="svgcircle" > 
                <rect id="circle1" x="5" y="25" width="50" height="50" stroke="#0E0E0E" style="fill:red; stroke-width:1" />
                 <text id =txtcircle x="5" y="35" font-family="Verdana" font-size="11" fill="white" > Rect1 </text>
            </svg> 

I also want to change text (ID = 'Rect1') by writing desired text with JavaScript.

Upvotes: 0

Views: 1899

Answers (1)

Amit Joki
Amit Joki

Reputation: 59232

You can do this

var elem = document.getElementById('txtcercle');
elem['innerText' in elem ? "innerText" : "textContent"] = "some value";

Upvotes: 2

Related Questions