As for the WHY i'm not sure but a li
tag shouldn't have a value
attribute. You should use data-* attribute instead. It is invalid/improper HTML syntax.
As shown below
<ul>
<li class="first" data-value="45">fortyfive</li>
<li class="second" data-value="4text5">45</li>
</ul>
var whatIsValue = $('.first').data('value');
var whatIsSecondValue = $('.second').data('value'); // = 4text5 typeof = string
var whatIsInputValue = $('input').val();
Update
Apparently in HTML5 once can use a value attribute, see comments below. In that case to solve this you could use the .prop() or .attr() methods.
Another Update
Because in HTML5 the value attribute on a li
is of type integer/number by default. As to why it trims the string to 4, that's a mystery.