sree sree - 2 months ago 6
HTML Question

Change type of an Input element using jquery

I am trying to change type of input, specifically after click into input I need to change

type="text"
to
type="date"
.

<input type="text" placeholder="DOB" id="dob" name="dob" />
<script>
$("#dob").click(function () {
$(this).attr('type', 'date');

});
</script>


I want to accomplish this for a iphone App. This is not working in iphone 4. How can do this?

Answer

Use this code :

<input type="text" placeholder="DOB" id="dob" name="dob"  />
<script>
   $("#dob").click(function(){
        $(this).prop('type', 'date');

  });

Here is the fiddle : http://jsfiddle.net/HNKkW/