cnotethegr8 cnotethegr8 - 1 year ago 67
Javascript Question

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

Using jQuery i would like to run a function when either

are raised.

Something like this.

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


Sorry i forgot to mention. Both
need some of the variables to be in-scope.

Answer Source

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!