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
0
votes
6 answers

jQuery .on click event does not occur

Hi and thanks for reading. I've been trying to avoid using HTML onclick="__" references and instead putting these events in my .js file. After reading about jQuery's .click() and then .on() events, I tried to use this in my code for a button. …
jason lee
  • 35
  • 7
0
votes
1 answer

Appending data from a handler loaded after the script

I've made a site that displays a user's Facebook photos. The code below appends the photos to the div "facebook-images". This part works fine. The problem I have is that the images are being appended after the Javascript code below is loaded; so the…
Dol
  • 944
  • 3
  • 10
  • 25
0
votes
1 answer

live() and on() method, and FF browser

I have this code that use live method, and it works in Opera and Chrome: $(".dynamicaly_created_div").live("click",function(){ $(event.target).parent().remove(); }); But not in the FF. So i tried to replace "live" with "on" (i read somwhere…
SomeoneS
  • 1,207
  • 2
  • 19
  • 34
0
votes
2 answers

jquery unable to bind functions

I am trying to attach onBlur and onFocus handler to a SSN input field. However, I am seeing an error saying object has no method 'ON'. The code is at http://jsfiddle.net/H4Q5f/ As you can see, I commented out to figure out the details, however had…
Kiran
  • 5,478
  • 13
  • 56
  • 84
0
votes
2 answers

When changing DOM, .on doesn't work as expected

Here's the site I'm working on: http://cirkut.net/sub/northwood/popunder/ Essentially what I'm trying to do is after you hover over the dropdown, you can click on the four links on the side, and it changes the content based on what you selected. My…
Josh Allen
  • 987
  • 12
  • 30
0
votes
2 answers

Using jQuery .on vs. using .live?

Simple question, since version 1.7 of jQuery .live() has been deprecated in favor of .on(); however .on() does not seem to work on elements that are rendered via JavaScript and loaded into the DOM. So my question is, should .live() still be used or…
firedrawndagger
  • 3,573
  • 10
  • 34
  • 51
-1
votes
1 answer

on bind an input field that was generated using a ajax call

I am wanting to bind a input field that is generated into the page using ajax. I have tried a number of different jQuery codes and none of them give any type of success. Here are the codes I have used: $('#bookingcoupon').bind('input',…
Robert
  • 907
  • 4
  • 13
  • 32
-1
votes
3 answers

Adding elements to the DOM via ajax and keeping jQuery connected

I have always had an issue in case when elements added to the DOM through AJAX don't seem to get the relevant jQuery.on() handlers attached to them. So I ended up with re-adding the events to them in the AJAX complete function. But I always wondered…
Mat Kay
  • 508
  • 1
  • 11
  • 24
-1
votes
2 answers

jQuery Remove Dynamically Created Element Not Working

Here is the code and the jsFiddle http://jsfiddle.net/yh3rynab/1/ var i = 1; $('body').on('click', '#add_row', function () { if (i >4) { alert("No more"); return; } …
pee2pee
  • 3,619
  • 7
  • 52
  • 133
-1
votes
1 answer

Problems Using .on() with Dynamically Added Elements

I read that .live() has been deprecated, and that I should use .on instead. But .on doesn't seem to be working for elements added to the DOM. My script adds a table with any number of text boxes (input type="text"), and I want to run some script…
Jonathan Wood
  • 65,341
  • 71
  • 269
  • 466
-1
votes
2 answers

is it possible to attach load event to a DIV using jquery "on" inside a dynamically loaded content

I am trying to setup validation using the $('#form').validate. most examples use document.ready for this. since my page is dynamically loaded I cant use document.ready. Also most examples of $(#div).on('event') use the click event, is it possible…
krprasad
  • 359
  • 1
  • 4
  • 17
-1
votes
2 answers

How to access an
  • after removing it, and then adding it back again?
  • I remove an
  • by clicking on a delete_it div within it. In the same action, I append an
  • to the end of the list: $(".delete_it").on("click", function(e){ $(this).parent().remove(); $(".images_list").append("
  • user1063287
    • 10,265
    • 25
    • 122
    • 218
  • -1
    votes
    4 answers

    jQuery .on not working correctly

    I'm playing around with pagination and jQuery, my code first looked like this: $(function() { $(".pagination a").live("click", function() { $.get(this.href, null, null, "script"); return false; }); }); Then I noticed that…
    John Smith
    • 6,105
    • 16
    • 58
    • 109
    -1
    votes
    5 answers

    jQuery: .live() and .on() - live returns this as JS object, on return this as jQuery object?

    I want to replace an old .live() function with .on(). .live() var jqRow = $('#' + id + ' tr'); jqRow.live("click", function () { myFunction(this); return false; }); .on() var jqRow = $('#' + id + '…
    Keith L.
    • 2,084
    • 11
    • 41
    • 64
    -2
    votes
    1 answer

    I have 2 bind functions and when I run them, it's very slow

    I'm new at writing Javascript and jQuery. If I have two slider and they will effect each other when I move each one it's very slow I use 2 bind command on each slider Is the bind command will have slow performance? Here is my code:
    子維 宋
    • 85
    • 1
    • 11
    1 2 3
    11
    12