dimanche 22 août 2021

How do I select all p tags and make them visible when check box is clicked?

I want all the <p> elements to be displayed when the checkbox is checked and otherwise not displayed.

function change(){
    var nav = document.getElementById("navbar");
    var checkBox = document.getElementById("checkbox");

    if(checkBox.checked == true){
        nav.style.width = "300px";
    } else{
        nav.style.width = "70px";
    }
}
nav{
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 100px;
    height: 100%;
    transition: 0.3s;
    /* #63. change 2nd to -10px from -6px */
    box-shadow: rgba(136, 165, 191, 0.26) 4px 2px 10px 0px, rgba(255, 255, 255, 0.8) -4px -2px 16px 0px;
}

nav a{
    text-decoration: none;
}

nav li{
    list-style-type: none;
    display: flex;
    color:black;
}

nav p{
    display: none;
}

nav input{
    margin: 10px;
    position: absolute;
    width: 50px;
    height: 50px;
    opacity: 0;
    cursor: pointer;
}

nav input:checked + nav p{
    display: flex;
}
<nav id="navbar">
        <input onclick="change()" type="checkbox" name="" id="checkbox">
        
        <ul>
            <a href="#">
                <li>
                    <p>Home</p>
                </li>
            </a>
            <a href="#">
                <li>
            
                    <p>Summer</p>
                </li>
            </a>
        </ul>
    </nav>



Aucun commentaire:

Enregistrer un commentaire