• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

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

truonglv

Formerly Nobita.Kun
#1
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
#5
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
#6
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
#7
Indeed, data values read from the attributes but are cached/independent. You should use an approach consistent with the code reading the value.