jQuery - Find dynamically created element without events

后端 未结 2 690
借酒劲吻你
借酒劲吻你 2021-01-19 22:15

Tho this question has been asked before, and the answer is this:

$(\'#container\').on(\'click\',\'#dynamicElement\', function(){ /* the code */ });
         


        
2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-19 22:33

    If your new element is being added to the page inside the success callback, at that point you can call $('#dynamicElement')

    Using $('#dynamicElement') anywhere outside of the callback would not return the element since it had not been added to the DOM yet.

提交回复
热议问题