Passing in function to the .on function
Hey Guys. I am a little bit confused when passing in functions in the .on parameter. Why does the function that we pass in doesn't include an opening and closing parentheses??
For example i pass the function highlighted. (Got the code from a tutorial btw) and the function takes no parentheses. Doesn't jquery need that in order to tell if its a function. Why in other parts of the code we need to include parentheses in this we don't. Thanks
- <script type="text/javascript">
var eventTarget = $("#evtTarget") ;
$(function() {
eventTarget.on("mouseenter mouseleave", highlighted); // No parentheses when calling the function
eventTarget.click("click", function() {
eventTarget.off("mouseenter mouseleave", highlighted);
});
});
function highlighted () {
eventTarget.toggleClass("highlighted");
}