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 to notify listeners when a particular thing occurs. In the object-oriented paradigm, 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:

37891 questions
1675
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
  • 97,462
  • 20
  • 76
  • 81
1114
votes
13 answers

How can I trigger the same function from multiple events with jQuery?

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
  • 15,702
  • 15
  • 47
  • 66
1104
votes
9 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
  • 52,220
  • 42
  • 131
  • 173
1080
votes
20 answers

How to find event listeners on a DOM node in JavaScript or in debugging?

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
  • 11,187
  • 4
  • 21
  • 22
737
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
  • 28,465
  • 32
  • 91
  • 105
673
votes
19 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
  • 17,157
  • 35
  • 107
  • 145
626
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
  • 20,543
  • 37
  • 111
  • 164
598
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,337
  • 4
  • 19
  • 15
565
votes
20 answers

Click event doesn't work on dynamically generated elements