What is different between $(document).on() and $(element).on()

后端 未结 2 1219
-上瘾入骨i
-上瘾入骨i 2021-02-05 12:55

I know about jquery .on() use and purpose, because I use it.

But I want to know what is the difference between $(document).on() vs $(element).on()

2条回答
  •  半阙折子戏
    2021-02-05 13:44

    $(document).on('click','.btn-edit',function()
    

    This binds a click event to the document and all child elements within it. This method is referred to as delegated event handling.

    $('#table-user').on('click','.btn-edit',function()
    

    binds the click event to the #table-user directly. captures the event directly on the element.

提交回复
热议问题