I'm a big fan of using jQuery's delegated event handling signature:
$('.container').on('click', '.button', function () {
// do something
});
I'm also a big fan of using the multiple event handler signature:
$('.container').on({
click: function () {
// do something
},
mouseover: function () {
// do something else
}
});
I'm wondering whether there's a way to combine the two together. I want to be able to handle click events on multiple different descendants of the same root element.
My first guess was that I could pass a second argument to the handler functions, but an inspection of the arguments variable showed no additional data coming in besides the event object.
Is there a design pattern to accommodate this or do I just have to bite the bullet and continue doing this?
$('.container')
.on('click', '.button-a', function () {
// do something
})
.on('click', '.button-b', function () {
// do another thing
})
.on('click', '.button-c', function () {
// do yet another thing
});