Jquery和隐藏div的点击 [英] Jquery and Hide a div on a click

查看:165
本文介绍了Jquery和隐藏div的点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题与JQuery。

i have a little problem with JQuery.

好吧,我有一个,我想隐藏这个div,当用户点击一个区域不在像在Facebook中的通知行为。

Well, i have a and i want to hide this div when an user click in a zone that is not in the like the "notifications" behavior in facebook.

我发现的解决方案是使用jQuery.live()方法,但我认为有一个更好的方法来做。

The solution that i found is to use jQuery.live() method but i think there is a better way to do it.

谢谢。

推荐答案

假设:

<div class="notification">You have 3 new messages</div>

使用:

$(document).click(function(evt) {
  if ($(this).closest("div.notification").length == 0) {
    $("div.notification").fadeOut();
  }
});

基本上,这会侦听所有点击。如果收到一个没有发生在通知div内的信息,它会将其淡出。

Basically this listens to all clicks. If one is received that doesn't occur inside a notification div it fades them out.

这篇关于Jquery和隐藏div的点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆