Home Web Front-end HTML Tutorial Detailed explanation of examples of js stopping bubbling

Detailed explanation of examples of js stopping bubbling

Jun 24, 2017 pm 02:04 PM
javascript js example stop bubble

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8 ">
<title>qypt15</title>
<style>
div {
background-color: green;
border: 1px solid;
padding: 50px ;
}
</style>
</head>
<body>

<p>The example demonstrates bubbling when adding different event listeners Different from captured. </p>
<div id="myDiv" onclick="myDiv()">
<p id="myP" onclick="myP()">Click on the paragraph, I am bubble. </p>
</div><br>
<div id="myDiv2" onclick="myDiva()">
<p id="myP2" onclick= "myPa()">Click on the paragraph, I am capturing. </p>
</div>
<script>
function myP(e) {
alert("You clicked on the P element!");
window.event ? window.event.cancelBubble = true : e.stopPropagation();
}
function myDiv() {
alert("You clicked the DIV element!");
}
function myPa() {
alert("You clicked on the P2 element!");
}
function myDiva() {
alert("You clicked on the DIV2 element!");
}
</script>

</body>
</html>

The above is the detailed content of Detailed explanation of examples of js stopping bubbling. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to implement an online speech recognition system using WebSocket and JavaScript How to implement an online speech recognition system using WebSocket and JavaScript Dec 17, 2023 pm 02:54 PM

How to implement an online speech recognition system using WebSocket and JavaScript

Recommended: Excellent JS open source face detection and recognition project Recommended: Excellent JS open source face detection and recognition project Apr 03, 2024 am 11:55 AM

Recommended: Excellent JS open source face detection and recognition project

Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS Dec 17, 2023 pm 06:55 PM

Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems WebSocket and JavaScript: key technologies for implementing real-time monitoring systems Dec 17, 2023 pm 05:30 PM

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems

PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts Dec 18, 2023 pm 03:39 PM

PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts

JavaScript and WebSocket: Building an efficient real-time weather forecasting system JavaScript and WebSocket: Building an efficient real-time weather forecasting system Dec 17, 2023 pm 05:13 PM

JavaScript and WebSocket: Building an efficient real-time weather forecasting system

Simple JavaScript Tutorial: How to Get HTTP Status Code Simple JavaScript Tutorial: How to Get HTTP Status Code Jan 05, 2024 pm 06:08 PM

Simple JavaScript Tutorial: How to Get HTTP Status Code

The relationship between js and vue The relationship between js and vue Mar 11, 2024 pm 05:21 PM

The relationship between js and vue

See all articles