• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Dynimically add step to linear gradient of an svg with javascript

Resolved: Dynimically add step to linear gradient of an svg with javascript

0
By Isaac Tonny on 18/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I’m trying to add some step to a linear gradient tag inside an svg with js.
My code works, meaning the markup is correct after the script run, but the svg is not updated/re-rendered.
I start with something like this
and in my js code i do a simple loop on a color array
The code works, i can see the step inside the linear gradient but the svg is not updated. If i put the step manually in the svg it clearly works, and if later in the code i try to manipulate the steps whit js, the svg get updated.
I’ve read some stuff about suspendRedraw, but also that is deprecated and may not apply to this case.
Does anybody has any suggestion?


Answer:

For SVG elements, you need to use Document.createElementNS() instead of createElement(). The correct namespace to pass in for the first param is 'http://www.w3.org/2000/svg'.


If you have better answer, please add a comment about this, thank you!

html javascript svg
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Passing 2 functions in onChange in react

24/03/2023

Resolved: Why doesn’t stringstream consume output during hex formatting?

24/03/2023

Resolved: CMake path for python3 libraries doesn’t change (windows 10)

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.