Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"change" in .live()

Tags:

jquery

I excavated this thread: JQuery live or something similar with .change()?

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

I had success in using .live() but for clicks. Now I need to do the same things for the change in drop down list selection.

Ideally I don't want to use any plugins, as suggested in the topic.

Does anyone has any ideas how to solve the problem?

like image 736
Eleeist Avatar asked Dec 11 '25 12:12

Eleeist


2 Answers

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

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

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

like image 120
Sampson Avatar answered Dec 14 '25 01:12

Sampson


Use .on() with the "delegated" syntax.

$(function ()
{
    $(document).on('change', 'select', function ()
    {
        // your event handling code here
    });
});
like image 26
Matt Ball Avatar answered Dec 14 '25 01:12

Matt Ball