I have an on click event on a parent element and an on click event on a child element. Each time I click on the child element, the on click associated with the parent element executes. Is there an easy way to allow my child element to be clickable?
<div class="main">
<div>Some Content</div>
<div>Some other Content</div>
<div class="seeterms">See Terms & Conditions</div>
...
<div class="terms">T&Cs</div>
</div>
$('.seeterms').on('click', function(){
$('html, body').scrollTop($(".terms").offset().top);
});
$('.main').on('click', function(){
doSomething();
});
2
Answers
Use this type of script to make it work.
Thanks.
filter the clicked element using
event.target
, i mean you can know if the parent element clicked but the cursor actually clicked on child, you can do it using something like this: