I have ran into extremely suprising behavior of some older jQuery that does not allow to modify svg
element width
or height
attributes (not styles). It just does not modify them and always silently fails.
It works fine with attributes like mywidth
, but not with width
.
Note that is related to some very old jQuery version (v1.4.3), but still I am just curious about reasoning behind that.
The setup is simple:
<svg id='mysvg'></svg>
and JS code:
$('#mysvg').attr('width','100');
does nothing, where:
$('#mysvg').attr('mywidth','100');
works fine.
I was supposing some other scripts overrides the changes and tried to affect the attribute after a timeout or on click, but behavior is still the same.
Also I've tried to put breakpoint on attribute modification in Chrome, but it also does not work, it triggers for .attr('mywidht','100')
but does not for .attr('width','100)
. It never generates a console error, always fails silently.
Is there any historical reason or unfamous bug that prevents modifying width and height attribute of svg
HTML tag?
Note that with some custom tag like <mysvg>
it works also fine and adds width attribute.
JSFiddle reproducing it: https://jsfiddle.net/d8703afx/
Looks like the attr('width')
returns some "special" [object SVGAnimatedLength]