javascript - Change display via click -
function sg() { x = document.getelementbyid("cai"); g = x.style.display; if (g == "none") { g == "block" } else { g == "none" }; } window.onload = zmena; function zmena() { document.getelementbyid("matek").onclick = sg; }
why isnt script working
firstly, can't assign value variable : 'g == "block"' . logical operation, not assignment. secondly, can wrap if else stuff in 1 string using short form, shown below :
function sg() { x = document.getelementbyid("cai"); x.style.display = x.style.display == 'block' ? 'none' : 'block' }
Comments
Post a Comment