I'm trying to make a function that making the password to be text if I click the eye, if you click again, the eye will close. I may use this function for other input, so I separate the function, so I do not use the way that eye.onclick=function(){...};
Below is my code, but my code only work one time, first time I click it, the eye open, but click again, the eye can not close, is that I need to remove the EventLister?
var password = document.getElementById('passWord');
var eye = document.querySelector('#eye');
var flag = 0;
var eyeOpen = function(obj,eyes,flag){
if (flag===0){
eyes.className="eye_open";
obj.type = 'text';
flag=1;
}else{
eyes.className = "eye_close";
obj.type = 'password';
flag = 0;
}
}
eye.addEventListener('click', function () {
eyeOpen(password,eye,flag);
});