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";} }

17th Sep 2016, 9:04 AM
ran gantz
ran gantz - avatar
2 Answers
+ 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" } }
17th Sep 2016, 9:32 AM
Zen
Zen - avatar
0
thank you very much!
17th Sep 2016, 9:30 AM
ran gantz
ran gantz - avatar