I have such script to create “div” using JavaScript:
[CODE]
function createDiv()
{
var newdiv = document.createElement(‘div’);
var divIdName = ‘div1’;
newdiv.setAttribute(‘id’,divIdName);
newdiv.style.width = “100px”;
newdiv.style.height = “100px”;
newdiv.style.left = “100px”;
newdiv.style.top = “100px”;
newdiv.style.position = “absolute”;
newdiv.style.background = “#FF0000”;
newdiv.style.border = “1px solid #000000”;
newdiv.innerHTML = ‘this is 1st DIV’;
document.body.appendChild(newdiv);
}
but I need to have few such DIVs on the page. They need to have the same width, height, background, border etc. so most of values will be common. The only thing which should be different would be text inside DIV and position of this DIV.
How can I rebuild this function to don’t need repeat whole script to create another DIVs and how could create exact DIV after onclick? I mean something like:
[CODE]
<a onclick=”createDiv(‘div1’)”>create 1st DIV</a>
<a onclick=”createDiv(‘div2’)”>create 2nd DIV</a>
<a onclick=”createDiv(‘div3’)”>create 3rd DIV</a>
Also I’m not sure how add option to remove created DIV. I’ll be grateful for help.