Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting viewBox attribute with jQuery [duplicate]

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?

like image 628
Ben Avatar asked Jul 23 '14 14:07

Ben


1 Answers

I solved this using @Mat's native Javascript setAttribute tip,

$('svg').removeAttr('viewBox');
$('svg').each(function () { $(this)[0].setAttribute('viewBox', '0 0 800 400') });
like image 56
Ben Avatar answered Nov 20 '22 07:11

Ben