jqueryHow do I use jQuery to execute code on page load?
Using jQuery to execute code on page load is quite simple. Here is an example code block that will alert a message when the page loads:
$(document).ready(function(){
alert("Page has loaded");
});
This will output a message saying "Page has loaded" when the page loads.
The code is composed of the following parts:
$(document)
- This is a jQuery selector that selects the document object..ready()
- This is a jQuery method that is called when the page is finished loading.function(){...}
- This is a JavaScript function that contains the code to be executed when the page is finished loading.alert("Page has loaded")
- This is the code that is executed when the page is finished loading.
Helpful links
More of Jquery
- How do I use jQuery ZTree to create a hierarchical tree structure?
- How do I use jQuery to zip files?
- How do I use jQuery to detect keycodes?
- How can I use jQuery to zoom an image when the user hovers over it?
- How do I use jQuery to zoom in or out on an element?
- How can I use jQuery to yield a result?
- How do I prevent XSS attacks when using jQuery?
- How can I make a jQuery XMLHttpRequest?
- How do I use jQuery Knob to customize user input?
- How do I use jQuery with Yarn?
See more codes...