0

I have an input type password that I want to change to text when an immage is clicked.

This is what I did:

$('#txtGenerate').attr("type", "text");

But it's not working.. What can I do?

2
  • Some browsers don't really support changing the type of an input element. You should consider replacing the password input with a text input instead. From the .attr documentation (which you read, right?): "Note: Attempting to change the type attribute (or property) of an input element created via HTML or already in an HTML document will result in an error being thrown by Internet Explorer 6, 7, or 8." Commented Jan 23, 2014 at 8:36
  • Works Fine here Commented Jan 23, 2014 at 8:38

3 Answers 3

3

You can do like this:

$('#txtGenerate').clone().prop('type','text').insertAfter('#txtGenerate').prev().remove();
  1. Clone the current input

  2. Change the input type

  3. Insert cloned input after old input

  4. Remove old input

Demo

Sign up to request clarification or add additional context in comments.

Comments

2

try this:

 $('#txtGenerate').prop('type', 'text');

1 Comment

Why should the OP try that? What's wrong with .attr?
1

Use prop instead:

$('#txtGenerate').removeAttr("type");
$('#txtGenerate').prop('type', 'password');

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.