-1

I've created a function where all drop downs on the page with the class ".dropdown" do something when changed. However adding subsequent dropdowns dynamically do not trigger the event. How can I make the dynamic dropdowns trigger the change event?

$(".dropdown").change(function () {
    //Do Something
});
Sven Hohenstein
  • 80,497
  • 17
  • 145
  • 168
Shazoo
  • 685
  • 12
  • 25

4 Answers4

0

You can use event delegation to attach change event for dynamically created .dropdown elements:

$(document).on('change', ".dropdown", function() {
    //Do Something
});
Felix
  • 37,892
  • 8
  • 43
  • 55
0
$(document).on('change', '.dropdown', function () {
    //Do Something
});

Structure is like

$(static selector / parent).on('event', 'dynamically added element*', function () {
    //Do Something
});

*also includes the currently existing ones

Spokey
  • 10,974
  • 2
  • 28
  • 44
0

use event delegation:

 $(document).on('change','.dropdown',function () {
//Do Something
});
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
0

try

$(".dropdown").live("change", function () {
            alert(1);
         });
Anoop Joshi P
  • 25,373
  • 8
  • 32
  • 53