Can anyone explain the weird jquery behaviour found in the following fiddle?
I have the following html...
<div id="test" data-prevy="0"></div>
With the following jquery...
console.log($('#test').data('prevy'));
console.log($('#test').attr('data-prevy'));
$('#test').attr('data-prevy', 2);
console.log($('#test').data('prevy'));
console.log($('#test').attr('data-prevy'));
$('#test').attr('data-prevy', 1);
console.log($('#test').data('prevy'));
console.log($('#test').attr('data-prevy'));
Which outputs...
0
0
0
2
0
1
When I would expect it to output...
0
0
2
2
1
1
I realize that if you set the value via .data (IE: .data('prevy', 2);) that the value will not reflect in the DOM, but I am doing the opposite and getting even more unexpected results.