开发者

javascript create and append element function not work

this is my javascript function :

function createLink (){
    var link = document.createElement("a");
    link.href = "#";
    var linkText = document.createTextNode("This is dynamic link");
    link.appendChild(linkText);
    document.body.appendChild(link);
}

window.onload =开发者_JS百科 createLink;

but i am not get any result from this. any one know, what is wrong with my code?


What you have works, you can test it here. Make sure that whenever you're running this isn't after window.onload has already fired, otherwise it won't run.

Also, make sure something else isn't stealing the onload event, and setting the handler to something other than createLink, for example a window.onload = otherFunction later down the line.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜