Say I have two click handlers which perform the same functionality :
$('#div1').click(function(event) {
alert('here');
});
$('#div2').click(function(event) {
alert('here');
});
How can I combine these two handlers into one instead of repeating the call to alert ?
Something like :
$('#div1').click.('#div2').click(function(event) {
alert('here');
});
Try this:
Furthermore, if you have a lot of
divelements, contained in a common parent, you may take benefit of event delegation and attach a single handler to the parent itself, like so: