LoginSignup
13

More than 5 years have passed since last update.

【jQuery】SVGのviewBoxでハマる

Posted at

jQueryの、attrメソッドは自動的にlowercase(小文字化)するため、SVGのviewBox(viewboxではなく)属性を変更できない。
そのため、以下のようにsetAttributeを利用し、設定する必要がある。

fail
$("#mySVG").setAttribute("viewBox","0 0 1000 1000");
success
document.getElementById("mySVG").setAttribute("viewBox","0 0 1000 1000");

※自動で小文字化するのは、HTMLに準拠しているためである。 SVGを使うことを考慮していないため対応しないのだろう。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13