Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

DOM doesn't change fill color

ANSWERED

Hi guys

I am having this weird issue with my code. What I want to do is to use DOM in order to change the fill color of a circle in SVG. However, the thing is that the circle's color doesn't change and stays the color I created it as. What's even more strange is that to debug I logged the fill color of the circle after the color change. I saw that the circle's fill color accessed via DOM was the color I wanted it to be, but the color change wasn't shown on the watch display. Here is my SVG code:

 

<circle cx="50%" cy="50%" r="20" fill="black" id="foo" />

and here is my JS code:

import document from "document";
var someCircle = document.getElementById("foo");
someCircle.fill = "#00FF00;

Can anyone tell me why this isn't working, and how to fix it? Thanks! 

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

Untested:

someCircle.style.fill
Peter McLennan
Gondwana Software

View best answer in original post

Best Answer
0 Votes
4 REPLIES 4

Hi guys

I am having this weird issue with my code. What I want to do is to use DOM in order to change the fill color of a circle in SVG. However, the thing is that the circle's color doesn't change and stays the color I created it as. What's even more strange is that to debug I logged the fill color of the circle after the color change. I saw that the circle's fill color accessed via DOM was the color I wanted it to be, but the color change wasn't shown on the watch display. Here is my SVG code:

 

<circle cx="50%" cy="50%" r="20" fill="black" id="foo" />

and here is my JS code:

import document from "document";
var someCircle = document.getElementById("foo");
someCircle.fill = "#00FF00;

Can anyone tell me why this isn't working, and how to fix it? Thanks! 

Best Answer
0 Votes

Untested:

someCircle.style.fill
Peter McLennan
Gondwana Software
Best Answer
0 Votes
Thanks, it actually works!
Best Answer

*phew* Smiley Wink

Peter McLennan
Gondwana Software
Best Answer
0 Votes