Why click event not work when I click a image at runtime?

Posted by jin on Stack Overflow See other posts from Stack Overflow or by jin
Published on 2010-03-22T03:48:29Z Indexed on 2010/03/22 3:51 UTC
Read the original article Hit count: 301

Now I am developing a Firefox extension , and when web page I want to create a image at runtime, now I can show the image , but When I click it to invoke a method , why it is not work? it is my code:

var _img = doc.createElement("img");

_img.setAttribute("id", "floatImage");

_img.setAttribute("src", "abc.jpg");

_img.setAttribute("onclick", "clickimage()");

document.body.append(_img);

function clickimage() { alert("click"); }

© Stack Overflow or respective owner

Related posts about firefox-extension

Related posts about JavaScript