cnotethegr8 cnotethegr8 - 6 months ago 24
Javascript Question

jQuery 'if .change() or .keyup()'

Using jQuery i would like to run a function when either

.change()
or
.keyup()
are raised.

Something like this.

if ( jQuery(':input').change() || jQuery(':input').keyup() )
{
alert( 'something happened!' );
}


EDIT

Sorry i forgot to mention. Both
.change()
and
.keyup()
need some of the variables to be in-scope.

Answer

you can bind to multiple events by separating them with a space:

$(":input").bind("keyup change", function(e) {
    // do stuff!
})

docs here.

hope that helps. cheers!