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

truonglv

Formerly Nobita.Kun
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);
 

rellect

Well-known member
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').
 

truonglv

Formerly Nobita.Kun
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').
 

Mike

XenForo developer
Staff member
Indeed, data values read from the attributes but are cached/independent. You should use an approach consistent with the code reading the value.
 
Top