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 can I get the y position of an element using jQuery?
- How can I use JQuery with Yii2?
- How do I use the jQuery masked input plugin?
- How do I uncheck a checkbox using jQuery?
- How can I convert jQuery code to vanilla JavaScript?
- How can I convert XML data to JSON using jQuery?
- How can I use jQuery to control the visibility of an element?
- How do I use the jQuery UI Datepicker?
- How do I use jQuery to trigger an event?
- How do I use jQuery to toggle an element?
See more codes...