- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
What is an Event Object in jQuery?
The callback function takes a single parameter; when the handler is called the JavaScript event object will be passed through it.
The event object is often unnecessary and the parameter is omitted, as sufficient context is usually available when the handler is bound to know exactly what needs to be done when the handler is triggered, however there are certain attributes which you would need to be accessed.
Let us see an example of isDefaultPrevented() method. The isDefaultPrevented() method checks whether event.preventDefault() was ever called on this event object.
Example
You can try to run the following code to learn how to work with even object in jQuery:
<html> <head> <title>jQuery isDefaultPrevented() method</title> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script> $(document).ready(function() { $("a").click(function(event){ if ( event.isDefaultPrevented() ){ alert( "Default behavior is disabled - 1" ); }else{ alert( "Default behavior is enabled - 1" ); } event.preventDefault(); if ( event.isDefaultPrevented() ){ alert( "Default behavior is disabled - 2" ); }else{ alert( "Default behavior is enabled - 2" ); } }); }); </script> </head> <body> <span>Click the following link and it won't work:</span> <a href = "https://www.google.com">GOOGLE Inc.</a> </body> </html>
Advertisements