Posted at

javascript

More than 3 years have passed since last update.


動的に要素追加

function add(args)

{
for(var i=0; i<=args.length; i++) {
var div_element = document.createElement("div");
div_element.innerHTML = i;
var parent_object = document.getElementById("test");
parent_object.appendChild(div_element);
}
}
</script>
</head>

<body>

<div>
<button onclick="add([1,2,3]);">test add</button>
</div>

<div id="test">
</div>

</body>
</html>