-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
  • 78,180
  • 16
  • 134
  • 160
Shazoo
  • 613
  • 11
  • 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,443
  • 7
  • 40
  • 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,894
  • 2
  • 27
  • 44
0

use event delegation:

 $(document).on('change','.dropdown',function () {
//Do Something
});
Milind Anantwar
  • 79,642
  • 23
  • 92
  • 120
0

try

$(".dropdown").live("change", function () {
            alert(1);
         });
Anoop Joshi P
  • 24,863
  • 8
  • 29
  • 52