3

before three years I was a javascript guru. After the JQuery release I forgot everything about JavaScript. This may be a great drawback of this framework, for me. LOL

My issue How I bind a function with the onload event of the document? I tried so far is:

<script type="text/javascript">
    var d = document.getElementsByTagName('body');
    d.onload=function(){
        alert('Welcome');
    }
</script>

also I tried document.onload = function() etc etc but none works

2 Answers 2

8

It's

window.onload

actually. You don't use the onload property of the body element, nor of the document object.

In action:

http://jsfiddle.net/5CP7Z/

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

Comments

1

You can use window.onload function. Some code to explain

function load() {  
    alert("load event detected!");  
  }  
  window.onload = load;  

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.