when you do parseInt('4text5')
it also returns 4 because that's how this function works.
http://www.w3schools.com/jsref/jsref_parseint.asp
I guess jqueries val() method is using parseInt somewhere but I'm not sure. It sure is something similar.
Also it make sense that the value of a list is an integer and the value of an input field (type text) is a string. isn't it?
javascript/jquery probably doesn't check the type you actually put in the field. If you want a number from an input field you need to set the type to number <input type="number">
thats why there are that many "meaningful" html elements. javascript expects that you use these elements for what they are designed for.
The way the value is extracted (as string, number, date etc) is depended on the HTML (or other markup language).
So the more I think about it the more it makes sense that the .val() method is returning a particular "type" depending on the dom element type.
- li -> default value is integer (it is a list with a defined number of li elements so it would be odd/strange that it would be a string)
- input[text] -> string
- input[number] -> integer