I am trying to cut duplicate code in JQUERY, but I canโt figure out how to call the function from the on-> click function.
My function looks like this:
function myCheckAll(div, closer, finder){ console.log(div+closer+finder); $(div).closest(closer).find(finder).prop('checked', this.checked); }
And I'm trying to call it something like this
$("#check_all_0").on('click', myCheckAll("#check_all_0", "table", "input#val0"));
My problem is that it does not work. I dont understand what:
1) I define the function outside the brackets ready for the document. This is where I should define it?
2) When I load the page, the console log is called. Without clicking the target, and it does not call the function if I click on the target.
I am new to jquery and probably doing something completely wrong, but would appreciate any help. Thank you
source share