Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery call function after load

Tags:

jquery

Need to call a filter function on some options based on a radio selected (Link here), How can I call this after the page is loaded? the radio is set from a DB call and I would like to filter the options

like image 366
Phill Pafford Avatar asked May 20 '09 20:05

Phill Pafford


People also ask

How do I run a function when a page is loaded in jQuery?

$( document ). ready() ready() will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute. Code included inside $( window ). on( "load", function() { ... }) will run once the entire page (images or iframes), not just the DOM, is ready.

How can we call a method after page load in jQuery?

after page loading? Method 2: Using the ready() method: The ready() method in jQuery is used to execute code whenever the DOM becomes safe to be manipulated. It accepts a handler that can be passed with the function required to be executed. It will now invoke the function after the page has completed loading.

How do I run a function after page load?

To get this event you should write following way: document. addEventListener('DOMContentLoaded', function() { // your code here }, false);

How do I ensure jQuery is loaded?

In general, you just use the following basic "document loaded" test in jquery. Straight from the beginners jquery tutorial: $(document). ready(function() { // do stuff when DOM is ready });


1 Answers

$(document).ready(my_function); 

Or

$(document).ready(function () {   // Function code here. }); 

Or the shorter but less readable variant:

$(my_function); 

All of these will cause my_function to be called after the DOM loads.

See the ready event documentation for more details.

Binds a function to be executed whenever the DOM is ready to be traversed and manipulated.

Edit:

To simulate a click, use the click() method without arguments:

$('#button').click(); 

From the docs:

Triggers the click event of each matched element. Causes all of the functions that have been bound to that click event to be executed.

To put it all together, the following code simulates a click when the document finishes loading:

$(function () {   $('#button').click(); }); 
like image 53
Ayman Hourieh Avatar answered Oct 02 '22 14:10

Ayman Hourieh