JQuery .data() not working?

前端 未结 2 605
伪装坚强ぢ
伪装坚强ぢ 2020-12-02 18:09

Recently I was coding away, and I ran into a weird issue. I was attempting to assign a data attribute to a new element I had created (via jQuery), only to discover it would

2条回答
  •  猫巷女王i
    2020-12-02 18:50

    jQuery imports the data- attributes when the element is loaded, but does not access it afterwards. The elements are stored in a jQuery internal structure. From the API:

    The data- attributes are pulled in the first time the data property is accessed and then are no longer accessed or mutated (all data values are then stored internally in jQuery).

提交回复
热议问题