A chain of two jquery events

If I have an event handler, for example:

function A() {
 ...
}

You can assign more than one event:

$("#test1").keyup(A);
$("#test2").change(A);

But I am wondering if it is possible to do this with only one sentence, for example:

$("#test1").keyup, $("#test2").change (function () {
  ...
});
+5
source share
4 answers

Short answer? No. Long answer? Not at all.

Sorry for not receiving the answer you were hoping for. But the good news is that your code looks away from this restriction.

0
source
$("#test2").bind('keyup change', A);

/ change as for different elements and events - this:

$("#test1, #test2").bind('keyup change', A);

or

$("#test1").bind('keyup', A);
$("#test2").bind('change', A);

depending on what you expect. There is no simpler way

+3
source

, . .

$("#test1").keyup(A).parent().find("#test2").change(A);

http://jsfiddle.net/8RwZY/

:

$("#test1, #test2").eq(0).keyup(A).end().eq(1).change(A);

http://jsfiddle.net/8RwZY/1/

+2

, #test1,

$('#test1').change(A).keyup(A);

, 1 , - .

0

All Articles