V
V
Vitaly2015-09-24 11:54:26
JavaScript
Vitaly, 2015-09-24 11:54:26

How in internet explorer 8, in the input field, change the type attribute from password to text and vice versa?

I'm trying to make a button, by clicking on which, the entered password will be hidden or shown.
In normal browsers via attr('type',"text") и attr('type',"password")
everything works fine. Now I need to get this to work in IE 8

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2015-09-24
@alexey-m-ukolov

The field type cannot be changed for security purposes. You can only replace it with a copy:

$passwordField = $('.your-selector');

attribites = {
  id: $passwordField.attr('id'),
  type: $passwordField.attr('type') === 'password' ? 'text' : 'password',
  name: $passwordField.attr('name'),
  value: $passwordField.attr('value'),
  class: $passwordField.attr('class'),
};

$passwordField.replaceWith($('<input/>', attribites));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question