Jquery .on versus .live

前端 未结 4 467
梦谈多话
梦谈多话 2020-12-09 15:58

I know that .live() is now deprecated but I cannot seem to change it and keep the functionality.

I just have a quick question about the

4条回答
  •  抹茶落季
    2020-12-09 16:35

    Try this:

    $('table tr th').live("click", function() {
    

    should be

    $(document).on("click", "table tr th", function() {
    

    That is how you would mimic the .live call exactly. You could of course limit your selector from document to something more meaningful based on your DOM structure.

    Edit:

    Just to clarify, in your example, you are required to use $(document).on(... because the table doesn't have any parents and is replaced during the life of your page.

提交回复
热议问题