1

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 = createLink;

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

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.