jeudi 1 octobre 2015

Show/Hide div function not working

I'm making a website for school but i'm stuck on a problem with my javascript. I'm new to javascript so it's probably something very simple so please humor me.

In the css I have set display to "none" for the element with id navigatie. If i remove the else{} part the code works but with it it doesn't. Does Anybody know what i'm doing wrong?

this is my code:

<!DOCTYPE html>
<!--gemaakt door Timo Vossen D01-->
<html>
    <head>
        <title>Straight Outta Compton</title>
        <link rel="stylesheet" type="text/css" href="sac.css">
        <meta name="keywords" content="Gerecht">
        <meta name="author" content="Timo Vossen">
        <meta name="description" content="Straight Outta Compton fanpage">
        <meta charset="UTF-8">
        <body onload="homeFunction()">
    </head>

    <script type="text/javascript">
        function showhide(){
            var nav = document.getElementById("navigatie");
            if(nav.style.display = "none"){
            nav.style.display = "block";
            }
            else{
            nav.style.display = "none";
            }
        }
    </script>

    <body>
        <div id="navigatie">
            <ul class="navigatiebar">
                <li class="knop"><a href="#">Home</a></li>
                <li class="knop"><a href="#">Movie</a></li>
                <li class="knop"><a href="#">Actors</a></li>
                <li class="knop"><a href="#">N.W.A</a></li>
                <li class="knop"><a href="#">Media</a></li>
            </ul>
        </div>

        <input type="checkbox" id="navigatieknop" onclick="showhide()" class="navigatieknop" />
        <label for="navigatieknop"></label>
        <div class="website">
            <div id="inhoud">
                <div id="beschijving">
                    <h1 class="text">Straight Outta Compton (2015)</h1><br>
                    <p class="text">In the mid-1980s, the streets of Compton, California, were some of the most dangerous in the country. When five young men translated their experiences growing up into brutally honest music that rebelled against abusive authority, they gave an explosive voice to a silenced generation. Following the meteoric rise and fall of N.W.A., Straight Outta Compton tells the astonishing story of how these youngsters revolutionized music and pop culture forever the moment they told the world the truth about life in the hood and ignited a cultural war.</p>
                </div>
                <div id="videos">
                    <iframe width="100%" height="100%" src="https://www.youtube.com/embed/rsbWEF1Sju0" frameborder="0" allowfullscreen></iframe>
                </div>
                <div id="quote">
                    <h1 class="text"><q>If we keep goin' we can take over the goddamn world!</q></h1><br>
                    <p class="text">-Dr. Dre</p>
                </div>
                <div id="producers">
                    <img src="img/universal.png" id="uni"></img>
                    <img src="img/legendary.png" id="leg"></img>
                </div>
                <!--<div id="footer">
                </div>-->
            </div>
        </div>
    </body>
</html>

Aucun commentaire:

Enregistrer un commentaire