mardi 2 mai 2017

Javascript hide/show div on passed term

Either 'y' or 'n' is passed into my javascript. I need to show a div within my HTML if 'y' is passed, and hide it if 'n'. I currently have this beneath.

<script type="text/javascript">
    if(category = 'y'){
            var x = document.getElementsByClassName("mydiv");
            x.style.display = 'block';
    }else
            x.style.display = 'none';

</script>
<html>
<div class="mydiv">
  <p><h1>Weather</h1></p>
</div>

</html>

The div is always being displayed and the term is being ignored, where am I going wrong? Thanks

Aucun commentaire:

Enregistrer un commentaire