我有这样的HTML标记
<div class="outside">
<div class="wrapper">
<div class="content-wrap">
<div class="content">
<div class="content-container">
<div class="text">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </p>
</div>
</div>
</div>
</div>
</div>
</div>
我希望当在content-wrap div的外部单击鼠标时,content-wrap div应该被隐藏。在我的标记中,您可以看到在内容包装之前,我刚刚使用了两个分别称为outside和wrapper的div。但实际上,在内容换行之前,我有很多div。如果单击了内容换行的任何子div,则不应隐藏该div。有人可以告诉我该怎么做吗?任何帮助和建议将是非常可观的。
这是fiddle link
最佳答案
您可以在stopPropagation()
的click事件上调用.content-wrap
以防止操作冒泡:
$('div.content-wrap').click(function(e) {
e.stopPropagation()
});
$("body").click(function(){
$(".content-wrap").fadeOut();
});
FIDDLE