Eses
Eses

Reputation: 15

show div when click and hide it when you click again

I want to hide and show my div when I click on li. It shows the div but don't hide it.

Here is my link to my code: this is my code

html

<ul>
    <li onclick="change(0)">itime1</li>
    <div id="li0">Eshow this</div> 
    <a href="#" onclick="change(1)"><li>item2</li></a>
    <div id="li1">show this</div>
</ul>

css

#li0 {
    display:none;
}
#li1 {
    display:none;}

javascript

function change(id) {
    var e = document.getElementById('li' + id);
    if (id === 0 || id === 1) {
        if (e.display = "none"){ 
            e.style.display="block";
        }
        else{
            e.style.display="none";
        }
    }
}
}

Upvotes: 0

Views: 782

Answers (1)

Anik Islam Abhi
Anik Islam Abhi

Reputation: 25352

Convert this

if (e.display = "none")

to this

if (e.style.display == "none")

You need the .style and the ==. You could also use ===.

Upvotes: 1

Related Questions