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.
精彩评论