I'm trying to make a password field, which when clicking an image next to it, will leave the password visible, and with that I also want to change the image when the click occurs.
My HTML looks like this:
<img src="~/Imagens/olho.jpg" style="width:7%;" align="right" onclick="mostraSenha(this)" id="img"/>
My javascript function looks 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>
Is there any way to check the content in my src attribute? That is, check when it is as "/images/leon.jpg" or as "/images/green-photo.jpg".