All other answers are correct - fixing 'val'
to val
- that of course solves the NaN
issue.
The problem however is:
I cannot set incremented data-id to HTML Element via jQuery. I'm able to alert the same, But I failed to set in HTML. There is no change in the element if I inspect.
jQuery uses internal representation (1) for data
. If you want to see data-id
in inspector you need to use:
$(this).attr('data-id', num);
(1) "Internal represenation":
All data is stored inside a property of the jQuery object named cache. Log the contents of $.cache in your console to see all data and events associated with any DOM element.