The problem:
jQuery objects html5 custom attributes DATA is being cached.
In my application I have a form with a field that has a changing custom data attribute, and this specific behavior is imperative for the functionally of the form.
What we have here:
There is an input field with some default custom attribute:
<input type="text" name="xxx" data-test="4">
Get the custom attribute
for $('input').data()
the result would be { test="4" }
change custom attribute
$('input').attr('data-test','5')
Get the custom attribute - again
for $('input').data()
the result would STILL be { test="4" }
Question
How can I always make sure to get all the REAL custom attributes, there can be more than one on an element, using the $.data()
function? I have tried the $.removeData()
before each fetch, but it cleans all the data completely from the element so it isn't accessible any longer.