[Solved] Why this jquery select doesn’t work? [closed]


You can do it like this with jquery – having to convert it back into a dom element

$('#email')[0].type="password";​​​​​​
// or using .prop $('#email').prop('type','password');​​​​​​

http://jsfiddle.net/68ZPh/

or just plain js

document.getElementById('email').type="password";

http://jsfiddle.net/tHWwZ/

As mentioned in the comments, this may cause issues in IE..

From jQuery .attr() docs

Note: jQuery prohibits changing the type attribute on an or element and will throw an error in all browsers. This is because the type attribute cannot be changed in Internet Explorer.

Another way would be to create a new input to replace it with

$('#email').replaceWith('<input type="password" id="email"/>');

http://jsfiddle.net/uVXvk/

1

solved Why this jquery select doesn’t work? [closed]