Click anywhere except the element to hide the element js

Source: Internet
Author: User

For example, to implement a click-list pop-up filter, click anywhere else to turn off the filter,

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/996160/201705/996160-20170517182726322-2007648649. PNG "style=" border:0px; "/>


The Filter class name

$ (document). Click (function  ()  {      $ (". submenu"). Hide ();});  $ (". submenu"). On ("click", function  (Event)  {      //Cancel event bubbling       var e = arguments.callee.caller.arguments[0] | |  event; //If this sentence is omitted, the following e is changed to Event,ie run can, but other browsers are incompatible       if  (e  && e.stoppropagation)  {          //  this code is for mozilla and opera           e.stoppropagation ();      } else if  ( window.event)  {          // this code is  for ie          window.event.cancelbubble =  true;      }}); 

You can successfully implement the requirement by first clicking anywhere in the document to hide the element and then binding the click event to the element to prevent bubbling to that element.


Click anywhere except the element to hide the element js

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.