1

I'm trying to show a password in an input field when I hover my mouse over it and after 1 second change it back to password.

This is what I have:

if (this.type === 'password') {
  this.type = "text";
  setTimeout(function () {
    this.type = "password";
  }, 100)
}

It changes the password to text, but doesn't change it back. I'm trying to do it this way to stop the code changing all text fields to passwords.

Any idea how I can do this ?

Thanks

Shiladitya
  • 11,650
  • 15
  • 23
  • 35
Tom
  • 1,360
  • 20
  • 41

1 Answers1

1

Change your code to

if (this.type === 'password') {
  this.type = "text";
  var that = this;
  setTimeout(function () {
    that.type = "password";
  }, 1000)
 }

Hold the this reference into a variable & use it inside setTimeout.

Hope this will help you.

Shiladitya
  • 11,650
  • 15
  • 23
  • 35