Changing Attribute "type" from text to password

This is a security measure that most major browsers employ to mitigate screen-reading and password theft (it's more important going the other way, from password to text).

I can't tell from your code what you're trying to do, but here's my guess: you want a textbox with the word Password in it as a hint, and when it gets focus, the user enters their password as a password field. To accomplish this, you can use two elements: an <input type="text"> and an <input type="password">, the latter hidden initially. When the user focuses on the textbox, simply hide it, show the password field, and set the focus. It could get tricky toggling back and forth between them.

Update

This is now way easier to accomplish in modern browsers. Simply use something like this (here's a jsFiddle):

<input type="password" placeholder="Password" />

Yes u can.

Try this its works

<input type="text" class="pwd">
  $('.pwd').click(function(){
  $(this).get(0).type='password';
});

'type' property/attribute cannot be changed.

edit: This was accurate for JQuery at the time it was posted. See other answers for how it can be done now.

Tags:

Jquery