JS Bubbling event Pee

Source: Internet
Author: User

What is a bubbling event? Simply put, the event is like a bubble in the water, triggering the current object and then triggering its parent element, then the parent element ...

eg

<div class= "Out" onclick= "alert (' Out ')" >
<div class= "Middle" onclick= "alert (' Middle ')" >
<input class= "inner" type= "button" onclick= "alert (' inner ')"/>
</div>
</div>

Click button, pop-up inner, middle, out.

Which element is terminated?

From the current element step up, some browsers end in document, there are window.

How do I block bubbling events?

<div class= "Out" onclick= "alert (' Out ')" >
<div class= "Middle" onclick= "alert (' Middle ')" >
<input class= "inner" type= "button" onclick= "alert (' inner ')"/>
</div>
</div>

<script>

function A (event) {
Alert ("inner");

Compatible with IE
Event.stoppropagation? Event.stoppropagation ():(event.cancelbubble= true);
}

</script>

This will only eject the inner

Note: Someone on the net said return false; and Event.preventdefault () can also prevent bubbling, pro-test, invalid ...

JS Bubbling event Pee

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.