JS Event bubbling

Source: Internet
Author: User

Sometimes we don't want bubbles or default events to happen, so it takes some jquery methods to block bubbles and default events.  There are three ways to prevent different levels of blocking. A:return false--->inEventHandler, preventsdefaultBehavior andEventbubbing. return falsein the handling of events, you can block the default events and bubbling events. B:Event. Preventdefault ()---> InEventHandler, preventdefault Event(allows bubbling). Event. Preventdefault () in the handling of the event, you can block the default event but allow the bubbling event to occur. C:Event. Stoppropagation ()---> InEventHandler, prevent bubbling (allowsdefaultbehavior). Event. Stoppropagation () in the handling of the event, you can prevent bubbling but allow the default event to occur. Code such as: $ ('. Menu Li'). Click (function () {$ ( This). Find ('ul'). Toggle (); return false;//Remove the trial effect})  --------------------------------------------------------------------------------------------------------------- -------------------JS code block event bubbling//Judging browser type, ie bubbles down, Firefox bubbles upfunction Stopevent (e) {e= e | | Window.Event; if(e.stoppropagation) e.stoppropagation (); ElseE.cancelbubble =true; if(E.preventdefault) E.preventdefault (); ElseE.returnvalue =false; }  

JS Event bubbling

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.