Reputation: 6603
Here is sample jquery code
$(document).ready(function(){
$('#myId').change(function(){
regularJSfunc('data1','data2');
});
}
now i want to trigger function call of $('#myId').change , can i do it through java script ?
Upvotes: 1
Views: 112
Reputation: 49
Using trigger call this function immediately on load script. So better use triggerHandler:
$('#myId').bind('change', function(){
regularJSfunc( 'data1', 'data2' );
});
$('#myId').triggerHandler('change'); //call function
Upvotes: 0
Reputation: 268324
jQuery actually provides a way for you to do that:
$("#myId").trigger("change");
Or you could chain it only the code you already have to call it immediately:
$("#myId").on("change", function(){
regularJSfunc( 'data1', 'data2' );
}).trigger("change");
Upvotes: 6