I have found many questions in this regard, but none of the solutions were good for me. I keep experiencing a feature (issue in my case) when I have multiple elements stacked on eachother. I have a dom situation like this.
<div class="body" data-type="body" onclick="foo(this)">
<div class="container" data-type="container" onclick="foo(this)">
</div>
</div>
So when I click .body console.log shows correct element. When I click .container both the elements fire onclick event. Is there any way to overcome this? Or is there any possibility to add the listeners otherwise? My pure jquery approach looks like this. Of course when I use pure jquery I have no inline onclick.
function initSelectable(){
$('*[data-type]:not(.item-wrapper)').unbind('click').bind('click',function(){
console.log($(this));
});
}
Thank you for every suggestion and/or answer!