I now see that you can add hooks in jQuery so .val() can return a number. You can hook into val() using the following code:
$.valHooks.text={
get:function(elem){
var i=parseFloat(elem.value,10);
return (isNaN(i))?elem.value:i
}
}
Now val() of any input type text will return a string or number depending if it can be converted.
This might be confusing though because the input type is TEXT.
You could use $valHooks.number and set the input of type number but tried this in Firefox 20.0.1 and didn't work.
This because jQuery tries to get the hook using
jQuery.valHooks[ elem.type ]
Since FireFox will return "text" when asking for an elem.type of type "number" it'll not call your hook and return the elem.value property wich is string. This is probably a bug in FireFox as
elem.getAttribute("type")
returns "number"
A way to overcome this bug is to go into jQuery source code and change the following line:
hooks = jQuery.valHooks[ elem.type ] || jQuery.valHooks[ elem.nodeName.toLowerCase() ];
to
hooks = jQuery.valHooks[ elem.type ] || jQuery.valHooks[ elem.nodeName.toLowerCase() ]
|| jQuery.valHooks[ elem.getAttribute("data-type") ];
Now in your html you can specify a number input field by:
<input type="number" data-type="number" ...
And add a nubmer hook:
$.valHooks.number={...//see code above for the rest