How can I change the HTML input type attribute with password to text?
I would like to change the "input" type attribute of an HTML element, from type = "password" to type = "text".
I know it would be easier to find an item by ID, but not every page has the same ID to enter a password. How to target password input and change their internal value to text type.
I have several lines of JavaScript code:
a=document.getElementsByTagName("input");
a.setAttribute(type,text);
source to share
You can get the password field using the following query.
document.querySelector('input[type="password"]').type = "text";
If you are dealing with multiple fields, you can use querySelectorAll
and loop through them.
var pwds = document.querySelectorAll('input[type="password"]');
for (var i=0;i<pwds.length;i++){
pwds[i].type = "text";
}
source to share
The function is called document.getElementsByTagName
(with s) and gives a list of items. So you will need to refer to it with the index ( a[0]
for the first input, etc.)
I think the problem is in determining which of the inputs you will need to change if they are not marked with IDs.
source to share