Trying to change input
type attribute from password
to text
.
$(\'.form\').find(\'input:password\').attr({type:\"text\"
my solution:
$('#myinput').clone().attr('type','tel').insertAfter('#myinput').prev().remove();
It's 2018 and jQuery does support this feature now. The following will work:
$('.form').find('input:password').attr("type","text");
This is pretty easy thou. This works pretty fine.
$('#btn_showHide').on('click', function() {
if($(this).text() == 'Show')
{
$(this).text('Hide');
$('#code').attr('type', 'text');
}
else
{
$(this).text('Show');
$('#code').attr('type', 'password');
}
});
I know I'm a little late to the game, but I was just able to do this in IE9 (it appears that Microsoft decided to allow it?). However, I had to do it with straight JavaScript. This is just a sample of a form with a dropdownlist that changes the field type depending on what is selected in the dropdown.
function switchSearchFieldType(toPassword) {
$('#SearchFieldText').val('');
if (toPassword === true) {
$('#SearchFieldText').get(0).setAttribute('type', 'password');
} else {
$('#SearchFieldText').get(0).setAttribute('type', 'text');
}
}
$('#SelectedDropDownValue').change(function () {
if ($("select option:selected").val() === 'password') {
switchSearchFieldType(true);
}
else {
switchSearchFieldType(false);
}
}).change();