jquery - How to prevent click function if certain child is clicked? -


fiddle

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

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

node.js - Bad Request - node js ajax post -

uitableview - Create and use custom prototype table cells in xamarin ios using storyboard -