unsure about .on() method

后端 未结 2 1114
面向向阳花
面向向阳花 2021-01-13 06:13

I was using the $.click() method for triggering some events. But then I needed to set some events for some HTML elements before the elements were declared. Let\

2条回答
  •  误落风尘
    2021-01-13 06:41

    You missed the three-argument version:

    $('body').on('click', 'div.hide', function() { ... });
    

    That puts the handler on the but it catches the events that bubble and invokes the handler when the target element matches the selector (the second argument).

    The handler doesn't have to go on the ; it can be any parent container element of your

    .

    The "on" method replaces the older "live" and "delegate" methods, as well as "bind" itself.

提交回复
热议问题