jQuery event.stopPropagation() Method

jQuery | event.stopPropagation() Method: Learn about the jQuery event.stopPropagation() Method with its usages, syntax, and examples.
Submitted by Pratishtha Saxena, on November 01, 2022

event.stopPropagation() Method

An event is an action occurred by the user. Therefore, many functions and methods can be set according to those actions performed. When these actions are defined for an event interface, we term those as the event properties. There are various predefined event properties in jQuery. Here, let's discuss the event.stopPropagation() method.

The event.stopPropagation() is a built-in method in jQuery. The event.stopPropagation() method allows the element to avoid the execution of the parent event handlers for the specific element. It prevents the bubbling of the events to the parent elements.

This means when a child element event is executed, then accordingly parent element event is also executed. Hence, to avoid this, event.stopPropagation() can be used which will only execute the selected element until the parent element event is triggered. We can also use event.isPropagationStopped() method to check whether event.stopPropagation() method has been called for the selected element or not.

event.stopPropagation() Method Syntax


This property takes in one required parameter – event. This event parameter is the one specified in the binding function. The below example shows how the event.stopPropagation() is triggered when the sentences are clicked.

jQuery event.stopPropagation() Method Example

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <h2>jQuery Event Property - Stop Propagation </h2>
    <div>Click the following sentences to implement the event.stopPropagation property of jQuery.</div>
    <h4 style="color:darkblue">Welcome to Include Help !</h4>
    <p>This is a jQuery Tutorial for Event Methods.
    <div>- Here we are discussing about <b>event.result</b> property. : [CHILD ELEMENT]</div>
    <h4 style="color:darkblue">Thanks for visiting !</h4>
  <script type="text/javascript">
            $('h3').html('H4 is has been Hovered.')
            $('h3').html('Paragraph tag has been Clicked.');
            $('h3').html('Div tag Clicked.');


Example 1: jQuery event.stopPropagation() Method

Comments and Discussions!

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.