lundi 31 août 2015

Javascript Else If Style Changing Issue

JS:

var div = document.getElementById('testdiv');
var button = document.getElementById('testbutton');

function showNotification(){
    if(div.style.display = "none") {
        div.style.display = "block";
    } else {
        div.style.display = "none";
    }
}

The code above simply shows and hides a div, Well thats what its meant to do but for some reason it wont hide using display: none when its set to display block. I also tried an else if statement but nothing will work.

P.S: I know I can just do 2 functions, hide/showNotification and just make it change the onclick from hide to show respectively but its not a great way to do it.

Aucun commentaire:

Enregistrer un commentaire