html - My JavaScript if...else statement isn't working properly -


so i'm new javascript, , i'm trying use simple if...else statement toggle between showing , hiding div element. html page looks this:

<!doctype html> <html>  <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>test</title> <style type="text/css"> #fluffy {             height:200px;             width:200px;             background-color:yellow;             display:block; } #pepper {             height:200px;             width:200px;             background-color:green;             display:block; } </style> </head>  <body> <div id="fluffy"></div> <div id="pepper" onclick="changestate()"></div> <script type="text/javascript"> function changestate() { var divstate = document.getelementbyid('fluffy').style.display; if (document.getelementbyid('fluffy').style.display == 'block') {     document.getelementbyid('fluffy').style.display = 'none'; } else if (document.getelementbyid('fluffy').style.display == 'none') {     document.getelementbyid('fluffy').style.display = 'block'; } else {     alert('test error message'); } } </script> </body>  </html> 

when load page in browser, receive alert box containing 'test error message'. original code had document.getelementbyid('fluffy').style.display stored in variable called divstate, didn't give me alert box, didn't anything. feeling i'm using == wrong or something, i'm not sure. i've used ===, , when didn't work switched ==, in code above.

if knows i'm doing wrong, appreciate help.

thanks, harold

alright, looks guys fixed problems. can't thank enough, , jquery!


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -