I have an <svg>
element on my page and would like to give it a viewBox attribute. When I try this with jQuery, like so:
$('svg').attr('viewBox', '0 0 800 400');
It almost works, but it gives the element a "viewbox" attribute (notice the lower case 'b'). This attribute requires the camel case to work, at least in Chrome where I have tested it. Are there any workarounds?
I solved this using @Mat's native Javascript setAttribute
tip,
$('svg').removeAttr('viewBox');
$('svg').each(function () { $(this)[0].setAttribute('viewBox', '0 0 800 400') });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With