Close a div by clicking outside

前端 未结 7 1006
感情败类
感情败类 2020-11-27 06:05

I want to hide a div by clicking on the close link in it, or by clicking anywhere outside that div.

I am trying following code, it opens and close t

7条回答
  •  野性不改
    2020-11-27 06:59

    This question might have been answered here. There might be some potential issues when event propagation is interrupted, as explained by Philip Walton in this post.

    A better approach/solution would be to create a custom jQuery event, e.g. clickoutside. Ben Alman has a great post (here) that explains how to implement one (and also explains how special events work), and he's got a nice implementation of it (here).

    More reading on jQuery events API and jQuery special events:

    • Introduction to custom events
    • jQuery event extensions

提交回复
热议问题