Search code examples
javascripthtmljquerygarbage-collectiongarbage

Html attribute value update but return first value all time as garbage


I am trying to set attribute for a Html label I am setting its value by jQuery on every change but when I try to get attribute value it return value first value that was assign to this attribute. Here are some code chunks for better understanding

<label class="" id="totalShortHours" name="totalShortHours">0</label>

On every change in time field it change attribute value that I can check in Developer tools element

enter image description here

But When I try to get value it return garbage

enter image description here


Solution

  • Using document.getElementById('totalShortHours').dataset.hours will resolve your issue.