Jquery click bind doesn't work second time

后端 未结 1 2001
星月不相逢
星月不相逢 2021-01-07 02:41

i have a strange behaviour with a and with img tag inside.

I have a php page with a table that is a list of records. At the end of every ro

1条回答
  •  伪装坚强ぢ
    2021-01-07 02:59

    You're using an ID selector #delete a which will only match one (generally the first) element.

    Try using a class, e.g. .delete a.

    The reason you only get one element is because JQuery optimizes any selector that begins with # passes through to document.getElementById, which only returns 1 element.

    Here's an example of how to use event delegation to achieve the same thing:

    $("#tableid").click(".delete a", function(e) {
        // your code
    });
    

    Your html would need to have an ID on your table and give class="delete" to the container of your delete links.

    0 讨论(0)
提交回复
热议问题