Questions tagged [jquery-on]

jquery on method can be used to bind events on dom elements. It also supports event delegation.

jQuery .on() attach an event handler function for one or more events to the selected elements. docs

$("selector").on( events [, selector ] [, data ], handler )

The .on() method attaches event handlers to the currently selected set of elements in the jQuery object. As of jQuery 1.7, the .on() method provides all functionality required for attaching event handlers.

Examples

// Example 1
$("div").on("click", function(){
  // do something
});
// Example 2
function notify() {
  // do something
}
$("button").on("click", notify);
// Example 3
$("input").on("keyup keydown", function(){
  // do something
});

Resource

166 questions
4
votes
1 answer

Binding a click event to content loaded via AJAX without making it delegated?

I have a situation where I am using the data attribute named data-command in many instances throughout a specific section of a site and instead of binding tons of separate click events I decided to just use the one and use a switch such…
Brett
  • 19,449
  • 54
  • 157
  • 290
4
votes
2 answers

backbone.js: how to stop event propagation among nested views

I'm looking for ways to make the views independent. So, the events of a view are constrained to that view, not going into the elements of the children nor the parent. The backbone.js framework binds the event on the top element of the view (view.el)…
4
votes
3 answers

jQuery on('hover') Event Replacement

I'm looking to swap an img src on hover. Typically I would use: $('#img').hover(function() { $(this).attr('src', 'http://www.example.com/new-img.jpg'); }); However, I'm loading the content in via Ajax so normally I would…
William Orazi
  • 1,694
  • 6
  • 23
  • 36
4
votes
3 answers

can't remove specific event handlers when attached to document with .on()

Here's a simple fiddle to demo my situation... http://jsfiddle.net/UnsungHero97/EM6mR/17/ What I'm doing is adding an event handler for current & future elements, using .on(). I want to be able to remove these event handlers for specific elements…
Hristo
  • 45,559
  • 65
  • 163
  • 230
4
votes
4 answers

JQUERY 'on' statement not working

I have a simple button that when clicked, changes its class. I have a second script which tries to detect that class being clicked again. They need to be able to be clicked on and off. //// Archive button clicked WORKS //// Un Archive button clicked…
Andy Webb
  • 121
  • 1
  • 9
4
votes
5 answers

jQuery - Converting .live to .on click

Possible Duplicate: jQuery 1.7 - Turning live() into on() .live() vs .on() method I have the following code (which I've simplified for this) which worked fine alongside jquery-1.7. $("td.ui-datepicker-week-col a").live("click", function () { …
Tom
  • 12,776
  • 48
  • 145
  • 240
4
votes
2 answers

jQuery .on() sometimes works, sometimes not

I have weird problem. At first I didn't want to use .on() method because I couldn't get it to work at all, so I used .live(). Now, I'm writing a new jQuery script and I used .on() heavily and it works. Until now. jQuery code: $('#artistList…
Kristjan O.
  • 814
  • 1
  • 9
  • 33
4
votes
1 answer

jquery $('body').on('click') always needs .off('click') to avoid multiple event firing

I have a page where I list my crew members (show_crew.php). The page runs on with infinite scrolling plugin, like Google Images does. At first, I show 10 entries. If the user reaches the bottom of show_crew.php, a new 'show_crew.php' is appended to…
Kinesias
  • 354
  • 1
  • 5
  • 18
3
votes
1 answer

Showing a loading image before an image is loaded with jQuery?

I've followed a few different similar questions here on SO but it's not working for some reason. Can someone help me understand why? I want the loading image to show first, then fade out when the bigger image is loaded. The bigger image should fade…
J82
  • 8,267
  • 23
  • 58
  • 87
3
votes
1 answer

Kendo Editor on