Friday, 15 February 2013

jquery call same function on various element and events -



jquery call same function on various element and events -

this question has reply here:

what's elegant way of binding multiple elements different event respectively using same event handler? 2 answers

actually need phone call same function on element1.change , element2.keyup

$("#element1").keyup(function(e){ }

and

$("#element2").change(function(e){ }

how declare function 2 events on 2 elements.

thanks

declare separate function , pass instead.

function handler(e){ // code; } $('#element1').keyup(handler); $('#element2').change(handler);

if have same event, can separate selectors comma or utilize add()

jquery

No comments:

Post a Comment