Unable to get jQuery on() to register dynamically added content

前端 未结 2 2038
孤城傲影
孤城傲影 2021-01-13 09:06

I\'m quite new to the on() method in jQuery but the time has come for me to need to use it.

I\'ve two functions for clicking on specific buttons. Each function works

2条回答
  •  感动是毒
    2021-01-13 09:25

    .on() essentially has two flavors: one which acts like .bind(), and another which acts like .delegate().

    For your problem, you want to use the delegate version. As a reference, on signatures are like this:

    // bind
    $(element-selector).on(event, handler)
    
    // delegate
    $(container-selector).on(event, element-selector, handler)
    

    The best way to get up to speed with this is probably to read up on delegate, what it is, how its used, and then apply that to on.

提交回复
热议问题