Home > Web Front-end > JS Tutorial > jquery prevents bubbling events using simulated events_jquery

jquery prevents bubbling events using simulated events_jquery

WBOY
Release: 2016-05-16 17:23:25
Original
1093 people have browsed it
Copy code The code is as follows:



Click to show hidden content

Here is the hidden content


<script> <br>$(document).ready(function(){ <br>$("span").bind("click", function(){ <br>$(".message").show(); <br>}); <br>$(".content").bind("click", function(){ <br>$(".message") .show(); <br>}); <br>$("body").bind("click", function(){ <br>$(".message").show(); <br>} ); <br>}); <br></script>
When span is clicked, all events of div and body are triggered. To prevent this from happening
$("span").bind("click", function(e){
$(".message").show();
e.stopPropagation(); //Complete event clearing action
});

Simulate event trigger
Copy code The code is as follows:

$(".content").bind("myclick", function(event,message1,message2){
$("#test").append(message1 messages2 );
});
$("#btn").trigger("myclick",["My Event","Triggered"]);
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template