Search code examples
javascriptjquerysvgattrlowercase

Does the attr() in jQuery force lowercase?


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?


Solution

  • 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","...");