Why is my jquery .on('change') not working for dynamically added selects

前端 未结 10 558
既然无缘
既然无缘 2020-12-31 01:12

I\'m adding select elements dynamically, like in the below HTML. I\'m not sure why the .on(\'change\' ...) is not working for the dynamic select. What am I missing?

<
10条回答
  •  佛祖请我去吃肉
    2020-12-31 01:54

    Correct syntax:

     $('#x').on(
            'change', 
             'select', 
              function () { 
                alert('helo'); 
              }
           );
    

    So syntax of on() for dynamic element seems:

    $(staticParent).on( eventName, target, handler);
    

提交回复
热议问题