SO - 16995645
by Arun P Johny
HTML
<div class="elem">Click here</div>
<div class="elem">Click here</div>
JavaScript
function attachClickToElem() {
$('.elem').filter(function(){
return !$(this).data('myclick-handler');
}).on('click.mytest', function () {
alert('Hello World');
}).data('myclick-handler', true);
}
$(function () {
attachClickToElem();
attachClickToElem();
});