All Questions

1468
votes
19answers
592632 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...
394
votes
8answers
358788 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 }); }...
345
votes
20answers
363171 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...
391
votes
10answers
464898 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?
677
votes
16answers
365163 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 ...
469
votes
13answers
318747 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....
190
votes
7answers
127028 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://..."); ...
646
votes
22answers
691019 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...
123
votes
17answers
299907 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...
232
votes
11answers
342994 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