Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
104
rated 0 times [  110] [ 6]  / answers: 1 / hits: 20026  / 8 Years ago, tue, june 21, 2016, 12:00:00

I want to change the class applied on an SVG with the click of a button. The code is here .



My SVG looks like:



<svg id=test class=fill xmlns=http://www.w3.org/2000/svg width=100% height=200px >
<path id=path22276 d=m500 81c-41-6-110-35-110-46 0-6 32 6 48 19 8 5 53 12 101 14 78 4 93 1 144-22 32-14 60-26 64-26 8 0-37 34-62 47-28 15-131 22-185 14z/>
</svg>


I tried both the below code :



  document.getElementById(test).className = halffill;
document.querySelector(svg.fill).setAttribute(class,halffill);


I tested the same javascript code against a normal div tag. It worked fine. Is there some restriction on SVG? Please help me figure this out.


More From » html

 Answers
21

The problem was the javascript load type was set to onload that made the function call on load of the body instead of onclick of the button.



Solution: You can see a gear icon on the top-right of javascript section. Click on it and change the load type to No wrap -in <head>


[#61694] Saturday, June 18, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nestorjarettg

Total Points: 451
Total Questions: 108
Total Answers: 108

Location: Rwanda
Member since Thu, Feb 10, 2022
2 Years ago
;