jQuery data() returns undefined, attr() returns integer

前端 未结 1 918
广开言路
广开言路 2020-12-03 02:45

I have the following code:

alert($embellishment.data(\"embellishmentId\"));
alert($embellishment.attr(\"data-embellishmentId\"));

The first

1条回答
  •  一生所求
    2020-12-03 02:58

    OK. I found the problem by interpreting jQuery docs.

    When you write:

    $embellishment.data("embellishmentId");
    

    it is handled by jQuery as compound attribute:

    So, to solve the problem you can use lower case in the data key otherwise it just addresses the different attribute.

    
    
    // JavaScript $embellishment.data("embellishmentid");

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