I saw an example comparison and I was in doubt about the reason for the operation.
In the comparison below, it removes the text and <button>
and compares in the if
to the check, whether it is true or false, but it never enters the true, even using ===
to compare. >
Apparently, at the time of getting the value it is "converting" ˅
and can not make the comparison.
function trocar(){
valor = document.getElementById('btnTrocar').innerHTML;
console.log(valor);
if(valor == "Imagem ˅"){
document.getElementById("btnTrocar").innerHTML = "Imagem ˂";
alert("Texto 1");
}
else{
document.getElementById("btnTrocar").innerHTML = "Imagem ˅";
alert("Texto 2");
}
}
<button onclick="trocar()" id="btnTrocar">Imagem ˅</button>
If this "conversion" exists:
- What's the reason for it?
- Why does it not treat as a "normal text"?
- Is there any way to get this button text, without changing anything?