1. 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

Discussion in 'Resolved Bug Reports' started by Nobita.Kun, Aug 27, 2015.

  1. Nobita.Kun

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

    MtoR Well-Known Member

  3. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    .data and .attr('data- is the same thing if I am not mistaken...
     
  4. Nobita.Kun

    Nobita.Kun Well-Known Member

    Just testing. Made new DOM then you call .data(). Then plan to change DOM value. Use .attr and .data to compare :)
     
  5. rellect

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

    Nobita.Kun Well-Known Member

    Yep! I have used attr('data-diff', 'xxx').
     
  7. Mike

    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.
     
    Nobita.Kun likes this.

Share This Page