I am having trouble to clear a concept; say I have the following code snippet:
$('a.classA').on('click', function(){
// something do here
});
$('a.classB').on('click', function(){
// something do here
$('a.classA').trigger('click');
// rest of the code
});
We know Javascript executes sequentially. So when the method corresponds to the click
event of a.classB
is executing, then the programmatic triggering of the click
event of a.classA
will pause the current method execution and when the click
event of a.classA
would finish then it will execute the rest of the code? Or the method will be executed in different thread or something; although threading is not available in Javascript.
Triggering a "click" is a synchronous operation, so it's effectively like making a function call. You can use a timeout with a zero-millisecond delay if you'd like the operation to take place after the current event loop completes.