edit in .live ()

I unearthed this topic: live jQuery or something similar with .change ()?

I have exactly the same problem as the person in this thread. I need to call change () on elements added () in the DOM.

I have had success using .live (), but for clicks. Now I need to do the same to change the dropdown list.

Ideally, I do not want to use any plugins as indicated in the topic.

Does anyone have any ideas how to solve the problem?

+3
source share
3 answers

As with jQuery 1.7, $.live()deprecated. You should use the new method $.on():

$("form").on("change", "select", function(){
  alert ( this.value );
});

Demo: http://jsbin.com/ahikov/edit#javascript,html

+3
source

.on() "" .

$(function ()
{
    $(document).on('change', 'select', function ()
    {
        // your event handling code here
    });
});
+1

If you have the latest version of jQuery installed, I recommend that you use the "on" method instead of "click", "change" to "live", etc. .... try to attach your event to the document:

    $(document).on('change', '.yourItem', function (e) {
        //Your code
    });
0
source

All Articles