- 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
Found 10711 Articles for Web Development
2K+ Views
To get attribute of an element, use the attr() method in jQuery. You can try to run the following code to get attribute of an element using the ‘click’ event −ExampleLive Demo $(document).ready(function(){ $("button").click(function(){ alert("Width of image: " + $("img").attr("width")); }); }); Get Width
158 Views
Commonly used event methods include $(document).ready(), click(), dblclick() etc. There is a list of methods which can be called on an Event Object, The following are some of the methods which can be called on an Event Object, S.NoMethod and Description1preventDefault() Prevents the browser from executing the default action.2isDefaultPrevented() Returns whether event.preventDefault() was ever called on this event object.3isPropagationStopped() Returns whether event.stopPropagation() was ever called on this event object.4stopImmediatePropagation() Stops the rest of the handlers from being executed.Let us see an example of stopPropagation() method. The stopPropagation() method stops the bubbling of an event to parent elements, preventing any parent handlers from being notified ... Read More
384 Views
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.NoProperty & Description1altKeySet 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.2ctrlKeySet to true if the Ctrl key was pressed when the event was triggered, false if not.3dataThe value, if any, passed as the second parameter to the bind() command when the handler was established.4pageXFor mouse events, specifies the horizontal coordinate of the ... Read More
264 Views
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.ExampleYou can try to run the following code to learn how to work with ... Read More
885 Views
Once an event handler is established, it remains in effect for the remainder of the life of the page. There may be a need when you would like to remove event handler.jQuery provides the unbind() command to remove an exiting event handler. The syntax of unbind() is as follows.The following is the description of the parameters −eventType − A string containing a JavaScript event type, such as click or submit. Refer to the next section for a complete list of event types.handler − If provided, identifies the specific listener that's to be removed.ExampleYou can try to run the following code to learn ... Read More
2K+ Views
To check the element type pf an event target, using the is() method.ExampleYou can try to run the following code to check the element type:Live Demo $(document).ready(function(){ $( "ul" ).click(function( event ) { var target = $( event.target ); if ( target.is( "li" ) ) { alert("Element is 'li'") } }); }); Click below to find out which element India US UK
9K+ Views
In this tutorial, we will learn how to handle bind an event using JavaScript. Events are the actions or occurrences in the system by the browser or users. There are various types of events that represent various activities performed by the browser or users. For example, if a user clicks on a button, it triggers an event named "click." Similarly, if a webpage finished loading, it triggered an event called "load." An Event Listener is a program that continuously listens to or waits for an event to occur. It is one of the most important parts of JavaScript. The ... Read More
543 Views
The bind( type, [data], fn ) method binds a handler to one or more events (like click) for each matched element. It can also bind custom events.Possible event values − blur, focus, load, resize, scroll, unload, click etc.Here is the description of all the parameters used by this method −type − One or more event types separated by a space.data − This is optional parameter and represents additional data passed to the event handler as event.data.fn − A function to bind to the event on each of the set of matched elements.ExampleYou can try to run the following code to learn how to ... Read More
3K+ Views
To handle a mouse right click event, use the mousedown() jQuery method. Mouse left, right and middle click can also be captured using the same method. You can try to run the following code to learn how to handle a mouse right click event:ExampleLive Demo $(document).ready(function(){ $('.myclass').mousedown(function(event) { switch (event.which) { case 1: alert('Left mouse button is pressed'); break; case 2: alert('Middle mouse button is pressed'); break; case 3: alert('Right mouse button is pressed'); break; default: alert('Nothing'); } }); }); Click me
861 Views
To handle a double click event using jQuery, use the dblclick() event. When an element is double clicked, this event occurs.ExampleYou can try to run the following code to learn how to handle double click event using jQuery −Live Demo $(document).ready(function(){ $("p").dblclick(function(){ alert("You have clicked this twice."); }); }); Double click