"ppp" is alerted in the moment of executing the statement newImg.onclick=klik("ppp"); and when clicking on the generated image nothing happens, even Javascript Console of Firefox stays blind.
function addNewImg(newImageId){ newImg = document.createelement('img'); newImg.id = "image"+newImageId; newImg = document.getElementById("divimage1").appendChild(newImg); var onC='ppEdit("image'+newImageId+'","image")'; document.getElementById("image"+newImageId).onclick=new Function(onC); }
it works
maybe an object detection be great to add too why? So browsers that understand document.getElementById, document.createelement execute the code.
function addNewImg(newImageId){ //object detection check if (!document.getElementById &&!document.createelement){return;} newImg = document.createelement('img'); newImg.id = "image"+newImageId; newImg = document.getElementById("divimage1").appendChild(newImg); var onC='ppEdit("image'+newImageId+'","image")'; document.getElementById("image"+newImageId).onclick=new Function(onC); }
alternative solution: if (!document.getElementById) {return;} document.getElementById("image"+newImageId).onclick=function(){ ppEdit(this.id, "image"); }