jQuery .on() click event catching dynamic 'data-' attribute in list of buttons to pass value to other function?

前端 未结 5 1192
误落风尘
误落风尘 2021-02-07 04:57

I have a dynamic table list of around 40 rows each with an edit button containing a date field. I also have the following click event script trying to attach to each button via

5条回答
  •  别那么骄傲
    2021-02-07 05:10

    You're not using the on function correctly. Here's one way you can do this: FIDDLE

    $('.showEdt').each(function () {
        var $this = $(this);
        $this.on("click", function () {
            alert($(this).data('evalz'));
        });
    });
    

    Also, notice you've written eValz instead of evalz on your code. Data attributes are case-sensitive so be careful with how you write them.

提交回复
热议问题