One click handler for multiple elements?
Posted
by user246114
on Stack Overflow
See other posts from Stack Overflow
or by user246114
Published on 2010-06-13T17:50:11Z
Indexed on
2010/06/13
17:52 UTC
Read the original article
Hit count: 162
jQuery
Hi,
I'm looking to add a click handler to a div. But is there a way to use a single click handler function and share it between multiple divs? Since I may have 100 divs, I don't want to create a click handler for each (they'll all practically do the same thing). The jquery example shows:
$("p").click(function () {
$(this).foo();
});
can we do something like:
$("p").click(myClickHandler);
function myClickHandler(source) {
source.foo();
}
?
Thanks
© Stack Overflow or respective owner