mardi 8 mai 2018

Updating Variable if that Variable is Equal to Value

I am working on a script that toggles a div. It does so by changing the max height between two values when clicked. The function is called using the onclick attribute on the div. I have data stored in an Object, which contains data related to this div. One piece of data is supposed to record of the div is expanded, and it is a Boolean. So my code looks something like this:

var data = {expanded:true};
function toggleDiv() {
    if (data.expanded == true) {
        //collapse div
        data.expanded = false;
    } else {
        //expand div
        data.expanded = true;
    }
}

The issue I am having is that for some reason the value of data.expanded isn't being updated. Any idea why? Am I misunderstanding how something works?

Aucun commentaire:

Enregistrer un commentaire