1
I’m trying to make a password field, which by clicking on an image next to it, will make the password visible, and with that also I want to change the image when the click occurs.
My HTML is like this:
<img src="~/Imagens/olho.jpg" style="width:7%;" align="right" onclick="mostraSenha(this)" id="img"/>
My javascript function is like this:
<script>
function mostraSenha(e) {
var x = document.getElementById("senha")
if (x.type === "password") {
x.type = "text";
} else {
x.type = "password";
}
if ($(e).attr("src") == "/Imagens/olho.jpg") alterarImagem('img', "/Imagens/olho-fechado.jpg");
else alterarImagem('img', "/Imagens/olho.jpg");
}
function alterarImagem(objeto, caminhoNovaImagem) {
document.getElementById(objeto).src = caminhoNovaImagem;
}
</script>
I am trying in "if ($(e). attr("src")" to verify the value contained in src, but this does not work. I tried to give a window.Alert but also does not open anything.
Is there any way to check the content in my src attribute? That is, check when it is "/Images/eye.jpg" or "/Images/closed-eye.jpg".
Man, thank you so much, it was logic error anyway! The only thing I had to change was the order, starting with the "/Images/eye.jpg", it should be in the function Else, worth! =)
– Bruno
Cool @Bruno! Glad I helped! I changed the answer with what you said! :)
– bio