2012-06-20 9 views

Respuesta

13
$(".parent").click(function(e) { 
    if (e.target == this) { 
     $(this).hide(); 
    } 
});​ 

DEMO:http://jsfiddle.net/Bt5HA/4/

+0

¡Ah! Maravillosamente simple, gracias. –

+0

@ChristianBenincasa De nada :) – VisioN

+0

http://stackoverflow.com/a/11124083/601179 – gdoron

0

Cambiar a:

$('.child a').click(function(e) { 
    $(this).parent('.child').hide(); 
});​ 
+0

que sólo funciona si se hace clic en el niño. ¿Qué sucede si se hace clic en el padre? – j08691

0

Trate Esta

$('#child').click(function(event) { 
event.stopPropagation(); 
alert('You clicked Child'); 
}); 


$('#parent').click(function() { 
alert('You clicked on Parent'); 
}); 

Puede comprobar trabajar aquí http://jsfiddle.net/VnHGh/24/

Cuestiones relacionadas