We would like to know how to add an id through setAttributeNode.
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
window.onload=function(){<!--from w w w . j a v a2 s.c o m-->
var setDivId=document.createAttribute("id");
setDivId.value=("div_"+5);
var node = document.createElement("div");
node.setAttributeNode(setDivId);
document.getElementById("resultContainer").appendChild(node);
var divIdNumber = ("div_"+5);
document.getElementById(divIdNumber).innerHTML='boxHTML';
}
</script>
</head>
<body>
<div id="resultContainer"></div>
</body>
</html>
The code above is rendered as follows: