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
$( 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.
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.
To get this event you should write following way: document. addEventListener('DOMContentLoaded', function() { // your code here }, false);
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 });
$(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(); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With