How to suppress jQuery event handling temporarily?



To suppress jQuery event handling temporarily, add a class to your element so that you can prevent further code from execution.

Example

You can try to run the following code to learn how to suppress jQuery event handling −

Live Demo

<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){     $(element).click(function(e) {         e.preventDefault();         // Check for fired class         if ($(this).hasClass('fired') == false) {           // Add fired class           $(element).addClass('fired');           // Remove fired class           $(element).removeClass('fired');           }    }); }); </script> <style> .fired {     font-size: 25px;     color: green; } </style> </head> <body> <h1>This is a heading</h1> <p class="fired">This is a paragraph.</p> <p class="fired">This is second paragraph.</p> </body> </html>
Updated on: 2020-02-14T12:34:23+05:30

756 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements