This article describes the method of dynamically creating divs in Javascript. Share it for your reference. The specific implementation method is as follows:
The code copy is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Native javascript creation div</title>
<script>
window.onload=function () {
var Odiv=document.createElement("div"); //Create a div
var Orpan=document.createElement("span"); //Create a span
Odiv.style.cssText="width:200px;height:200px;background:#636363;
text-align:center;line-height:220px"; //Create a css style for div
//Odiv.id="box"; //Create the id of the div as box
//Odiv.className="Box"; //The class of div is Box
Odiv.appendChild(Ospan); //Create a span in the div
document.body.appendChild(Odiv); //Create a div in the body
}
</script>
</head>
<body>
</body>
</html>
I hope this article will be helpful to everyone's JavaScript programming.