Questions tagged [events]

An event is a way for a class to provide notifications to listeners when a particular thing happens.

An event is a way for a class to provide notifications to clients of that class when some interesting thing happens to an object. The most familiar use for events is in graphical user interfaces; typically, the classes that represent controls in the interface. These classes have events that are notified when the user does something to the control (for example, click a button).


References

See also:

35772 questions
1676
votes
23 answers

Event binding on dynamically created elements?

I have a bit of code where I am looping through all the select boxes on a page and binding a .hover event to them to do a bit of twiddling with their width on mouse on/off. This happens on page ready and works just fine. The problem I have is that…
Eli
  • 88,788
  • 20
  • 72
  • 81
1045
votes
11 answers

jQuery multiple events to trigger the same function

Is there a way to have keyup, keypress, blur, and change events call the same function in one line or do I have to do them separately? The problem I have is that I need to validate some data with a db lookup and would like to make sure validation is…
shaneburgess
  • 14,832
  • 15
  • 44
  • 65
948
votes
8 answers

What's the difference between event.stopPropagation and event.preventDefault?

They seem to be doing the same thing... Is one modern and one old? Or are they supported by different browsers? When I handle events myself (without framework) I just always check for both and execute both if present. (I also return false, but I…
Rudie
  • 46,504
  • 37
  • 126
  • 167
917
votes
19 answers

How to find event listeners on a DOM node when debugging or from the JavaScript code?

I have a page where some event listeners are attached to input boxes and select boxes. Is there a way to find out which event listeners are observing a particular DOM node and for what event? Events are attached using: Prototype's…
Navneet
  • 9,549
  • 4
  • 19
  • 22
720
votes
24 answers

jQuery Event Keypress: Which key was pressed?

With jQuery, how do I find out which key was pressed when I bind to the keypress event? $('#searchbox input').bind('keypress', function(e) {}); I want to trigger a submit when ENTER is pressed. [Update] Even though I found the (or better: one)…
BlaM
  • 26,721
  • 31
  • 89
  • 104
580
votes
18 answers

How to trigger event in JavaScript?

I have attached an event to a text box using addEventListener. It works fine. My problem arose when I wanted to trigger the event programmatically from another function. How can I do it?
KoolKabin
  • 15,407
  • 35
  • 103
  • 144
579
votes
8 answers

How do I attach events to dynamic HTML elements with jQuery?

Suppose I have some jQuery code that attaches an event handler to all elements with class .myclass. For example: $(function(){ $(".myclass").click( function() { // do something }); }); And my HTML might be as follows:
frankadelic
  • 19,333
  • 31
  • 105
  • 161
574
votes
16 answers

jQuery find events handlers registered with an object

I need to find which event handlers are registered over an object. For example: $("#el").click(function() {...}); $("#el").mouseover(function() {...}); $("#el") has click and mouseover registered. Is there a function to find out that, and possibly…
ages04
  • 6,067
  • 4
  • 16
  • 15
527
votes
20 answers

Click event doesn't work on dynamically generated elements