Jquery trigger change event can be called with a few simple line of code. Let’s take an example, jquery on page load or jquery after page load, you just want to call an function which is onchange function of jquery.
Solution 1: With Jquery Onload Function
1 2 3 |
$("#yourElement").change(function(){ // your code here }).change() |
You can call the .change() event function on any regular jquery function having the above syntax. Put .change() function at the end of event and it will boom.
Solution 2: Jquery Trigger Change Event
1 2 3 4 5 6 7 8 9 10 11 12 |
$(function () { yourFunctionName(); //this calls it on load $("select#marca").change(yourFunction); }); function yourFunctionName() { var marca = $("select#marca option:selected").attr('value'); $("select#modello").html(attendere); $.post("select.php", {id_marca:marca}, function(data){ $("select#modello").html(data); }); } |
Here, as script gets run, the first block will execute the yourFunctionName() where you have initiated your calculation or jquery whatever your requirements are will be executed.
[[ Also, read Change Image Source Jquery blog post ]]
Solution 3: Jquery After Page Load
1 2 3 |
$(document).ready(function(){ onchange(); // onload it will call the function }); |
In this code, the first line is initiating and trigger the ready function of jquery when the page is ready, it will execute the body of this function.
Indirectly, this will execute the onchange() function which should be initiated somewhere.