Not a bug JS DateTime not get last value of Time and Diff

truonglv

Well-known member
As title. When i do update the DateTime element. The DateTime still get the old value.

Because this line:
Code:
thisDiff = parseInt($element.data('diff'), 10);
                thisTime = parseInt($element.data('time'), 10);

I think it should be:
Code:
thisDiff = parseInt($element.attr('data-diff'), 10);
                thisTime = parseInt($element.attr('data-time'), 10);
 
Do you use data() or attr() to update the value?
These functions store data differently, and are not in sync with each other's changes.
My guess is that you used attr('data-diff', 'xxx') to update the value, instead of data('diff', 'xxx').
 
Do you use data() or attr() to update the value?
These functions store data differently, and are not in sync with each other's changes.
My guess is that you used attr('data-diff', 'xxx') to update the value, instead of data('diff', 'xxx').
Yep! I have used attr('data-diff', 'xxx').
 
Indeed, data values read from the attributes but are cached/independent. You should use an approach consistent with the code reading the value.
 
Top Bottom