Buggy fade in/out code in JavaScript/CSS

mets

New Member
I'm not the most proficient in coding and have been stuck at trying to get this function working right for days and hope that someone could help me...The idea is for the red div to show by default and the blue/yellow divs to be called upon by pressing the 'fade 1' and 'fade 2' buttons. When either of the buttons are pressed the red div is hidden and wont be called for. The current code bugs up when the buttons are pressed continuously, they either wont show, the fade effect wont work or the red div appears.Thanks!\[code\] <!DOCTYPE html> <html> <head> <style type="text/css"> .myBtn { width:80px; } #myImg0 { -webkit-transition: opacity 0.5s ease-in; -moz-transition: opacity 0.5s ease-in; -o-transition: opacity 0.5s ease-in; position:absolute; background-color:red; width: 100px; height: 100px; } #myImg1 { -webkit-transition: opacity 0.5s ease-in; -moz-transition: opacity 0.5s ease-in; -o-transition: opacity 0.5s ease-in; position:absolute; background-color:blue; width: 100px; height: 100px; } #myImg2 { -webkit-transition: opacity 0.5s ease-in; -moz-transition: opacity 0.5s ease-in; -o-transition: opacity 0.5s ease-in; position:absolute; background-color:yellow; width: 100px; height: 100px; } #myImg1.fade-out { opacity:0; } #myImg1.fade-in { opacity:1; } #myImg2.fade-out { opacity:0; } #myImg2.fade-in { opacity:1; } .hide {display: none;} </style> <script type="text/javascript"> function fade1(btnElement) { if (btnElement.value =http://stackoverflow.com/questions/15868285/=="Fade Out") { document.getElementById("myImg0").className = "fade-out"; document.getElementById("myImg2").className = "fade-out"; btnElement.value = "http://stackoverflow.com/questions/15868285/Fade In"; } else { document.getElementById("myImg1").className = "fade-in"; btnElement.value = "http://stackoverflow.com/questions/15868285/Fade Out"; } } function fade2(btnElement) { if (btnElement.value =http://stackoverflow.com/questions/15868285/=="Fade Out") { document.getElementById("myImg0").className = "fade-out"; document.getElementById("myImg1").className = "fade-out"; btnElement.value = "http://stackoverflow.com/questions/15868285/Fade In"; } else { document.getElementById("myImg2").className = "fade-in"; btnElement.value = "http://stackoverflow.com/questions/15868285/Fade Out"; } } </script> </head> <body> <input class="myBtn" type="button" value="http://stackoverflow.com/questions/15868285/Fade 1" onclick="fade1(myImg1);" /> <input class="myBtn" type="button" value="http://stackoverflow.com/questions/15868285/Fade 2" onclick="fade2(myImg2);" /> <div id="myImg0" ></div> <div id="myImg1" class="hide" ></div> <div id="myImg2" class="hide" ></div> </body> </html>\[/code\]
 
Top