var divIDcounter=0; function add() { var newdiv,linkob,link,contents; newdiv=document.createElement('div'); contents=document.createTextNode('New Div LOLOMG'); linkob=document.createElement('a'); link=document.createTextNode('[rem]'); linkob.href='#'; // linkob.setAttribute('onclick','rem()'); linkob.onclick=rem; linkob.appendChild(link); newdiv.appendChild(contents); newdiv.appendChild(linkob); newdiv.setAttribute('name',newId()); // Add box alert(linkob.onclick); document.body.appendChild(newdiv); return true; } function rem() { parentNode.removeChild(this); } function newId() { divIDcounter = divIDcounter+1; return divIDcounter; }