Currently I have a bunch text inputs, which I can’t change the HTML for (as it is pre-generated), but I want to convert them from type=”text” to type=”number”, is there a bit of jQuery or JavaScript I can use to achieve this?
This is in a small application for mobile devices.
Basically I want to convert
<input type="text" id="MyID" name="MyName">
to
<input type="number" id="MyID" name="MyName">
I was trying something like
<script>
function DoWhenReady() {
$('#MyID').attr('type', 'number');
}
$(document).ready(DoWhenReady);
</script>
In the header, but without success – suggestions?
Try
$('#MyID').prop('type', 'number');(jQuery 1.6+ required forprop)