We experienced a problem using attr(“value”) JQuery function when selecting values that are not integers.
So if you have:
<ul>
<li id="li1" value="1">One</li>
<li id="li2" value="2">Two</li>
<li id="li3" value="3">Three</li>
<li id="li4" value="4">Four</li>
</ul>
It is working OK.
$(function() {
alert($('#li2').attr('value'));
});
But if you have (string as values instead of integers):
<ul>
<li id="li1" value="One">One</li>
<li id="li2" value="Two">Two</li>
<li id="li3" value="Three">Three</li>
<li id="li4" value="Four">Four</li>
</ul>
This is not working.
$(function() {
alert($('#li2').attr('value'));
});
Solution (rename value attribute to something else):
<ul>
<li id="li1" tag="One">One</li>
<li id="li2" tag="Two">Two</li>
<li id="li3" tag="Three">Three</li>
<li id="li4" tag="Four">Four</li>
</ul>
This is now OK.
$(function() {
alert($('#li2').attr('tag'));
});
Conclusion:
Do not use reserved attributes as your custom attributes (where HTML element does not support them).
