event.isPropagationStopped()

event.isPropagationStopped()

event.isPropagationStopped()Returns: Boolean

Description: Returns whether event.stopPropagation() was ever called on this event object.

This event method is described in the W3C DOM Level 3 specification.

Example:

Checks whether event.stopPropagation() was called

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>event.isPropagationStopped demo</title>
  <script src="https://code.jquery.com/jquery-1.10.2.js" rel="external nofollow" ></script>
</head>
<body>
 
<button>click me</button>
<div id="stop-log"></div>
 
<script>
function propStopped( event ) {
  var msg = "";
  if ( event.isPropagationStopped() ) {
    msg = "called";
  } else {
    msg = "not called";
  }
  $( "#stop-log" ).append( "<div>" + msg + "</div>" );
}
 
$( "button" ).click(function(event) {
  propStopped( event );
  event.stopPropagation();
  propStopped( event );
});
</script>
 
</body>
</html>

Demo:

© The jQuery Foundation and other contributors
Licensed under the MIT License.
https://api.jquery.com/event.isPropagationStopped

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部