All Questions

1397
votes
19answers
566963 views

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...
383
votes
8answers
344628 views

In jQuery, how to attach events to dynamic html elements?

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 }); }...
332
votes
20answers
348045 views

Click event doesn't work on dynamically generated elements

<html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function() { $("but...
379
votes
9answers
448901 views

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?
669
votes
16answers
356074 views

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 ...
460
votes
12answers
310620 views

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....
187
votes
7answers
124303 views

jQuery .live() vs .on() method for adding a click event after loading dynamic html

I am using jQuery v.1.7.1 where the .live() method is apparently deprecated. The problem I am having is that when dynamically loading html into an element using: $('#parent').load("http://..."); ...
641
votes
22answers
683753 views

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. [U...
122
votes
17answers
292122 views

How to capture the browser window close event?

I want to capture the browser window/tab close event. I have tried the following with jQuery: jQuery(window).bind( "beforeunload", function() { return confirm("Do you really want t...
227
votes
11answers
334999 views

How to stop event propagation with inline onclick attribute?

Consider the following: <div onclick="alert('you clicked the header')" class="header"> <span onclick="alert('you clicked inside the header');">something inside the header</span> &...

Previous Next