- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do I prevent jQuery events from bubbling up to parent elements?
To prevent jQuery events from bubbling up to parent elements, use the stopPropogation() method. The stopPropagation() method stops the bubbling of an event to parent elements, preventing any parent handlers from being notified of the event.
Example
You can try to run the following code to prevent jQuery events from bubbling up to parent elements −
<html> <head> <title>jQuery stopProagation() method</title> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script> $(document).ready(function() { $("div").click(function(event){ alert("This is : " + $(this).text()); event.stopPropagation(); }); }); </script> <style> div { margin:20px; padding:20px; border:2px solid #666; width:160px; } </style> </head> <body> <p>Click on any box to see the effect:</p> <div id = "div1" style = "background-color:green;"> OUTER BOX <div id = "div2" style = "background-color:gray;"> INNER BOX </div> </div> </body> </html>
- Related Articles
- How to stop the bubbling of an event to parent elements in jQuery?
- How to bind jQuery events on elements generated through other events?
- How to bind events on dynamically created elements using jQuery?
- How do I prevent an iOS device from going to sleep mode?
- How do I prevent an Android device from going to sleep mode?
- How do I shift from jQuery to core JavaScript?
- Which jQuery events do not bubble?
- How to remove all child nodes from a parent in jQuery?
- How to remove all child nodes from a parent using jQuery?
- How do I get the parent directory in Python?
- How to remove all child nodes from a parent node using jQuery?
- How do I prevent bleeding nose condition in summers?
- How to fire jQuery events with setTimeout?
- How to store and reproduce jQuery events?
- How to implement custom events in jQuery?

Advertisements