Search code examples
jqueryonkeyup

$('#searchfield').keyup(function(e){


i have a little question. Is it possible to call the keyup function with an extra value?

For example

$('#eld').keyup(function test(e,val2){
    test('','hallo');

But this will not work. Any ideas?


Solution

  • What you can do is, pass custom data through the .trigger() method of jQuery.

    For instance.

    $('#eld').keyup(function(e, val2){
      alert(val2);
    });
    

    Now you can trigger the keyup with

    $('#somebutton').click(function(){
        $('#eld').trigger('keyup', ['custom data']);
    });
    

    You can pass an array of custom data through .trigger() as second parameter.

    Example: http://www.jsfiddle.net/V9Euk/