I try to call a function in jquery with parameter such that
$(document).ready( function() {
$('#id_pros').bind('change', wordCounter('id_pros_wordCountLabel') );
});
function wordCounter(item){
....
}
If I don’t pass parameter id_pros_wordCountLabel it works great but now it didn’t call wordCounter.
Which part is wrong with my code ?
Thanks
.bind()expects a function argument, like this:Note how there are no parentheses on
wordCounter. This means that it’s a reference to a function, and not an invocation of a function — which is what happens when you add parentheses. Use an anonymous function to solve the problem:(I also changed
.bind('change', ...)to.change(...)which is equivalent but more concise.)