I am trying to use Javascript in order to add a canvas to one page which originally does not have one.
I am trying to do the following:
var canv=document.createElement("canvas");
canv.setAttribute("id", "canvasID");
alert(canv.id);
var c=document.getElementById("canvasID");
alert(c.id)?;
The problem is the the first alert(canv.id) results in canvasID, while the second alert is undefined because c is null.
Can anybody tell me what am I doing wrong?
PS: the code is designed to run under Greasemonkey so adding the canvas and its ID in the HTML itself is not a viable option.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…