1

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 ?

3
  • yes, you can do that, but if you want an example you have to tell us what '#myId' is. Commented May 19, 2012 at 5:13
  • 1
    You forgot to close you document ready, last line should be }); vs }. Commented May 19, 2012 at 5:15
  • jsfiddle.net/ipsjolly/c4QcW/3 Commented May 19, 2012 at 5:41

2 Answers 2

6

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");
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.