how to pass arguments to a jquery bind-event?
arguments, bind, jquery
Solution
You can use the `data` parameter to `.bind`:
$('#name').bind('keyup', {chars: 10}, countChars23);
and then in your function replace the declared parameter with `event` and put this in the first line:
var chars = event.data.chars;
EDIT the reason your second and third attempts (with the extra function wrapper) don't work is because they don't set `this` properly. You would have had to have called it like this:
$('#name').keyup(function() {
countChars23.call(this, 10);
}
Problem
Please can you help me, i don´t find a solution. I have a function with arguments and want to pass this function to a jquery bind-event: ``` function countChars23 (chars) { var thi = $(this); var len = $(this).val(); if (len.length >= chars) { len = len.substring(0, 22); thi.val(len); } } ``` Calling the function don´t work: ``` $('#name').bind('keyup', countChars23(10)); ``` This don´t work either: ``` $('#name').bind('keyup', function() { countChars23(10); } ``` This don´t work either: ``` $('#name').keyup(function() { countChars23(10); } ``` Many Thanks for your help!