简体   繁体   中英

How to hide and show all the content of a div with JavaScript?

For example, the div contains:

    <div id="choices">
            <ul>
                <li><button onclick="Correct('incorrect, try again!')">simple, easy</button></li>
                <li><button onclick="Correct('Correct! Congratulations!')">influence, advantage</button></li>
                <li><button onclick="Correct('incorrect, try again!')">premium, fine</button></li>
                <li><button onclick="Correct('incorrect, try again!')">contrary, opposite</button></li>

            </ul>
            </div>

I want to hide the content of this div completely with a function, and make it reappear with another function. Is that possible?

document.getElementById('choices').style.display = "none"; //hide
document.getElementById('choices').style.display = "block"; //show

You can use jQuery to accomplish the task too. With it you can use some effects too. Take a look: http://jsfiddle.net/davidbuzatto/wZTs7/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM