Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
186
rated 0 times [  192] [ 6]  / answers: 1 / hits: 42087  / 11 Years ago, wed, august 7, 2013, 12:00:00

I have a custom data-attribute set by default:



data-equipment=0



If i change it with jquery using .data()



$(this).data(equipment, 10)



and then use the getAttribute()



this.getAttribute(data-equipment)



i get the old value (0) and not the new one (10). But if i use



$(this).data(equipment) i get the new value (10).



Is this supposed to work like this or am i missing something?



Thanks!


More From » jquery

 Answers
16

.data() doesn't operate on data attributes but in internal jQuery cache. Initially if no cache record is found, the data is read from a corresponding data- attribute if one exists, but that is the end of their co-operation.



If it operated on attributes, it would be useless for its purpose because attribute values must be strings.


[#76476] Tuesday, August 6, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aileent

Total Points: 556
Total Questions: 107
Total Answers: 101

Location: Croatia
Member since Fri, Sep 11, 2020
4 Years ago
;