Get current SVG change value using javascript

I want to get the current "stroke" value for a specific svg element. This is not a problem if the value was set using javascript before, but when it is set by the class, I cannot seem to get the return value using the following scripts ...

el.getAttribute('stroke') //returns 'null'

el.setAttribute('stroke','red') // the stroke is visibly changed to 'red'

el.getAttribute('stroke') //returns 'red'

      

So how do I get the current value when set via style?

+3


source to share


1 answer


stroke is a CSS property, so if you want to see what stroke of an element no matter how it was set, that should do it ...



var stroke = window.getComputedStyle(el).getPropertyValue("stroke");

      

+3


source







All Articles