i've got an issue with my function. This is my example markup:
<div id="parent">
<div id="container">
<div id="childElement1">
</div>
<div id="childElement1">
</div>
<div>
</div>
now i've got this code:
$('div').on('mousedown','div',function(e){
e.stopPropagation();
switch(e.which){
//left mouse click
case 1:
break;
//middle mouse click
case 2:
break;
//right mouse click
case 3:
console.log(e.target);
break;
}
});
With that code I can select the Container element and also the child elements by right click (the child elements will be created on runtime). but I want to be able to select the Parent element too. So can anyone give me an Advice how to fix that ?
You just need to remove the 'div' filter.
$('div').on('mousedown',function(e){ ... }