Trying to change input
type attribute from password
to text
.
$('.form').find('input:password').attr({type:"text"});
Why this doesn't work?
$(document). ready(function() { // #login-box password field $('#password'). attr('type', 'text'); $('#password'). val('Password'); });
jQuery change() MethodThe change() method triggers the change event, or attaches a function to run when a change event occurs. Note: For select menus, the change event occurs when an option is selected.
To change the type of input it is (button to text, for example), use: myButton. type = "text"; //changes the input type from 'button' to 'text'. Another way to change or create an attribute is to use a method like element.
my solution:
$('#myinput').clone().attr('type','tel').insertAfter('#myinput').prev().remove();
You can't do this with jQuery, it explicitly forbids it because IE doesn't support it (check your console you'll see an error.
You have to remove the input and create a new one if that's what you're after, for example:
$('.form').find('input:password').each(function() { $("<input type='text' />").attr({ name: this.name, value: this.value }).insertBefore(this); }).remove();
You can give it a try here
To be clear on the restriction, jQuery will not allow changing type
on a <button>
or <input>
so the behavior is cross-browser consistent (since IE doens't allow it, they decided it's disallowed everywhere). When trying you'll get this error in the console:
Error: type property can't be changed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With