Skip to content

Instantly share code, notes, and snippets.

@nus
Created July 27, 2012 06:42
Show Gist options
  • Save nus/3186507 to your computer and use it in GitHub Desktop.
Save nus/3186507 to your computer and use it in GitHub Desktop.
SVGタグを動的に追加
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title>動的にSVGを追加</title>
<script type="text/javascript">
function addSvg()
{
var svg = document.createElementNS("http://www.w3.org/2000/svg", "svg:svg");
// document.createElement("svg");は画象として生成できない
svg.setAttribute("width", "640");
svg.setAttribute("height", "480");
document.body.appendChild(svg);
};
</script>
</head>
<body>
<input type="button" onclick="addSvg();" value="追加" />
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment