I create a svg
element in javascript and I need to set an attribute which is case sensitive: viewBox
.
The element is created like this: var svgElem = document.createElement('svg');
Problem is when it set that attribute via svgElem.setAttribute("viewBox", "0,0,100,100")
and append to the DOM, the resulting element shows like this:
<svg viewbox="0,0,100,100"></svg>
This doesn't work because the viewBox
is case sensitive, it will not take any effect if the letter B
is lowercase.
IE allows an IFlag parameter just for cases like these, however my target audience is restricted to FireFox and Chrome users, which do not have IFlag for setAttribute
as far as I could find.
Is there a way of making this work without using innerHTML
and no-library javascript?
EDIT: I have also tried using dot notation with no success svg.viewBox = "0,0,100,100"