Does the attr() in jQuery force lowercase?

bzuillsmith picture bzuillsmith · Sep 11, 2012 · Viewed 7k times · Source

I'm trying to manipulate the svg 'viewBox' attribute which looks something like this:

<svg viewBox="0 0 100 200" width="100" ...> ... </svg>

Using

$("svg").attr("viewBox","...");

However, this creates a new attribute in the element called "viewbox". Notice the lowercase instead of intended camelCase. Is there another function I should be using?

Answer

bzuillsmith picture bzuillsmith · Sep 11, 2012

I was able to use pure javascript to get the element and set the attribute by using

var svg = document.getElementsByTagName("svg")[0];

and

svg.setAttribute("viewBox","...");