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

jquery prevents bubbling events using simulated events_jquery

WBOY
WBOYOriginal
2016-05-16 17:23:251037browse
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"]);
Statement:
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