- 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 are event attributes in jQuery?
jQuery events have attributes such as for keyup and keydown events, if the Ctrl key was pressed, timestamp when the event created, etc.
The following are some of the event properties/attributes available:
S.No | Property & Description |
---|---|
1 | altKey Set to true if the Alt key was pressed when the event was triggered, false if not. The Alt key is labeled Option on most Mac keyboards. |
2 | ctrlKey Set to true if the Ctrl key was pressed when the event was triggered, false if not. |
3 | data The value, if any, passed as the second parameter to the bind() command when the handler was established. |
4 | pageX For mouse events, specifies the horizontal coordinate of the event relative from the page origin. |
5 | pageY For mouse events, specifies the vertical coordinate of the event relative from the page origin. |
Example
You can try to run the following code to learn how to work with jQuery event attributes:
<html> <head> <title>jQuery Attributes</title> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script type = "text/javascript" language = "javascript"> $(document).ready(function() { $('div').bind('click', function( event ){ alert('Event type is ' + event.type); alert('pageX : ' + event.pageX); alert('pageY : ' + event.pageY); alert('Target : ' + event.target.innerHTML); }); }); </script> <style> .div { margin:10px; padding:12px; border:2px solid #666; width:60px; } </style> </head> <body> <p>Click on any square below to see the result:</p> <div class = "div" style = "background-color:blue;">ONE</div> <div class = "div" style = "background-color:green;">TWO</div> <div class = "div" style = "background-color:red;">THREE</div> </body> </html>
- Related Articles
- What are Event Methods in jQuery?
- What are the methods in jQuery to manipulate attributes?
- What are jQuery Event Helper Methods?
- What is an Event Object in jQuery?
- What are the attributes in C#?
- What are conditional attributes in C#?
- What are obsolete attributes in C#?
- What are predefined attributes in C#?
- How to define multiple CSS attributes in jQuery?
- Can I wrap a JavaScript event in a jQuery event?
- What are built-in class attributes in Python?
- What are the DataTransfer object attributes?
- How to remove all style attributes using jQuery?
- How to filter object array based on attributes in jQuery?
- How to add attributes to an HTML element in jQuery?

Advertisements