JS Add and Remove Simple Instances of DIV
- 2021-07-02 22:57:17
- OfStack
JS Add and Remove Simple Instances of DIV
function addDiv(w,h){
// If there was " divCell "This layer, delete this layer first
deleteDiv();
// Create 1 A div
var my = document.createElement("divCell");
// Add to Page
document.body.appendChild(my);
// Specifies this by style div The location mode of , If you want to set it yourself div Location of , This sentence must have , Comment it out and you can know the effect ~ Give it a try
my.style.position="absolute";
// Specify by style x Coordinates ( Random number 0~450)
my.style.top= Math.round(Math.random()*450);
// Specify by style y Coordinates ( Random number 0~700)
my.style.left= Math.round(Math.random()*700);
// Specify width by style
my.style.width=w;
// Specify Height by Style
my.style.height=h;
// Specify the background color by style ,, If it is a background picture Examples are my.style.backgroundImage="url(img/3.jpg)"
my.style.backgroundColor="#ffffcc";
// Add div Content of
//my.innerHTML=i++;
// Set style transparency
my.style.filter = "alpha(opacity=50)";
// Settings ID
my.id = "divCell";
}
function deleteDiv()
{
var my = document.getElementById("divCell");
if (my != null)
my.parentNode.removeChild(my);
}