0
String compare
why this code not working? i want that by button click the text in id="logo" will change over and over. function myFunction(){ var a=document.getElementById("logo"); if(a.localeCompare("hide")==0){ document.getElementById("logo").innerHTML="show";} else{ document.getElementById("logo").innerHTML="hide";} }
2 odpowiedzi
+ 2
You have to compare the content of the element with id logo with "hide", not the element itself.
Try this:
function myFunction() {
var a=document.getElementById("logo");
if(a.innerHTML == "hide"){
a.innerHTML = "show";
} else {
a.innerHTML = "hide"
}
}
0
thank you very much!