I have an input type="text" that I want converted to an input type="button". I have tried attr(), but that does not work:
HTML:
<input type="text"></input>
JavaScript:
$('input').attr('type', 'button');
What’s wrong?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can’t change the
typeattribute with jQuery. This is from the jQuery source:The reason, according to the comment, is that it causes problems in IE. Since jQuery is designed to reduce complications that arise due to differences between browsers, it would go against that idea if it worked in other browsers. I’m assuming that’s why the jQuery team have simply removed that ability.
As has already been mentioned, your best option will probably be to replace the
inputelement in question with a new one.