I have several click
handlers on a carousel plugin (GitHub repo here).
When I initially coded it, I forgot about jQuery chaining:
$gallop.on("click", ".advance", function(){ [snip 1] })
$gallop.on("click", ".retreat", function(){ [snip 2] })
$gallop.on("click", ".autoplay", function(){ [snip 3] })
$gallop.on("click", ".picker", function(){ [snip 4] });
They're all on the same .gallop
element, so I am able to improve the code by chaining them together:
$gallop
.on("click", ".advance", function(){ [snip 1] })
.on("click", ".retreat", function(){ [snip 2] })
.on("click", ".autoplay", function(){ [snip 3] })
.on("click", ".picker", function(){ [snip 4] });
They're also all listening for the click
event: only the selectors are different for each handler. Is there a way to put multiple selector/handler items in the same .on()
method? Something like this?
$gallop
.on("click",
".advance", function(){ [snip 1] },
".retreat", function(){ [snip 2] },
".autoplay", function(){ [snip 3] },
".picker", function(){ [snip 4] });