Using live() - benefits - similar to bind()

前端 未结 3 1703
攒了一身酷
攒了一身酷 2020-12-15 11:07

I have been doing some reading up on jquery live event and am still kind of confused? What is the benefit to using it?

http://docs.jquery.com/Events/live

I k

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-15 11:25

    The benefit is that the event handler will also be added to new matching elements when those elements are created. This saves you from having to manually add the event handler every time you create a new element (matching a previously used selector) that needs it.

    Added in jQuery 1.3: Binds a handler to an event (like click) for all current - and future - matched element.

    From http://docs.jquery.com/Events/live#typefn, emphasis mine.

提交回复
热议问题