- 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
How to trigger the same function with jQuery multiple events?
To trigger the same function with multiple events, use the jQuery on() method with multiple events such as click, dblclick, mouse enter, mouse leave, hover, etc.
Example
You can try to run the following code to learn how to work the same function with jQuery multiple events:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("p").on({ mouseenter: function(){ $(this).css("background-color", "gray"); }, mouseleave: function(){ $(this).css("background-color", "red"); }, dblclick: function(){ $(this).css("background-color", "yellow"); } }); }); </script> </head> <body> <p>Click, double click and move the mouse pointer.</p> </body> </html>
- Related Articles
- How to fire jQuery events with setTimeout?
- How to use multiple versions of jQuery on the same page?
- How to bind multiple events with one "bind" in Tkinter?
- How to select multiple elements with jQuery?
- How to bind jQuery events on elements generated through other events?
- How can we create multiple MySQL triggers for the same trigger event and action time?
- How to store and reproduce jQuery events?
- How to implement custom events in jQuery?
- How to call jQuery function with JavaScript function?
- How to handle HTML5 media events using jQuery?
- How we can prioritize jQuery events?
- What is MySQL trigger and triggering events related to it?
- How to use multiple JavaScript libraries along with jQuery?
- How to wrap multiple divs in one with jQuery?
- Are jQuery events blocking?

Advertisements