I want to trigger one event on page load complete using javascript/jquery.
Is there any way to trigger event or call a simple function once page loading fully completes.
Please suggest folks if you any reference.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Everyone’s mentioned the
readyfunction (and its shortcuts), but even earlier than that, you can just put code in ascripttag just before the closingbodytag (this is what the YUI and Google Closure folks recommend), like this:At this point, everything above that script tag is available in the DOM.
So your options in order of occurrence:
Earliest: Function call in
scripttag just before closing thebodytag. The DOM is ready at this point (according to the Google Closure folks, and they should know; I’ve also tested it on a bunch of browsers).Earlyish: the
jQuery.readycallback (and its shortcut forms).Late, after all page elements including images are fully loaded:
windowonloadevent.Here’s a live example: http://jsbin.com/icazi4, relevant extract:
(Yes, I could have used jQuery for the
displayfunction, but I was starting with a non-jQuery template.)