rjg132234 rjg132234 - 3 months ago 14
jQuery Question

In jQuery, how do you add code to an already bound element?

I have an element (e.g

$('#elm')
) and it has a binding on it in the source code.

E.G.
$('#elm').on('touchstart', function(){ /* do stuff */ });


Now I am adding more code to the page and I want to add new functionality to the binding of the element, WITHOUT removing the previous
do stuff
code.

How can I add code to the #elm
touchstart
binding?

Answer
$('#elm').on('touchstart', function () { /* do stuff */ });
$('#elm').on('touchstart', function () { /* do other stuff */ });

Use as many event handlers as you like.