In a web application, I have found the following code (simplified):
$("#miInput").trigger("click");
$("#miInput").click();
Is there a difference between those two lines? Is it better to use one over the other? (and because)
In a web application, I have found the following code (simplified):
$("#miInput").trigger("click");
$("#miInput").click();
Is there a difference between those two lines? Is it better to use one over the other? (and because)
According to the jQuery code , it
.click()
is part of event aliases, which call.on()
or.trigger()
depending on whether or not there are arguments, respectively:That said, the only (minor) difference would be going through one less function using
.trigger("click")
.taken from here: https://stackoverflow.com/questions/9666471/jquery-advantages-differences-in-trigger-vs-click
Basically, if no parameters are passed to the "click", it ends up calling the "trigger" function. For this reason, trigger is faster.
Cheers,
Roger