jquery - How to prevent click function if certain child is clicked? -
for reason, not() in on() function not working. want function run if aqua section (parent) element clicked, , nothing if gray div (child) element clicked.
jquery:
$('body').append('<section><div class="someclass"></div><section>'); $('body').on('click', 'section:not(".someclass")', function(){ alert('aqua not gray clicked.'); }); also, why alert pop twice if section aqua element clicked?
you need check whether actual element clicked (e.target) has class:
if ($(e.target).hasclass('someclass')) return;
Comments
Post a Comment