Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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 ?
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('.myElement').click(function(e) {
e.preventDefault();
// Check for fired class
if ($(this).hasClass('fired') == false) {
// Add fired class
$(this).addClass('fired');
// Remove fired class after 2 seconds
setTimeout(function(){
$('.myElement').removeClass('fired');
}, 2000);
}
});
});
</script>
<style>
.fired {
font-size: 25px;
color: green;
}
.myElement {
cursor: pointer;
padding: 10px;
background-color: lightblue;
margin: 5px;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p class="myElement">Click me - This is a paragraph.</p>
<p class="myElement">Click me - This is second paragraph.</p>
</body>
</html> Advertisements
