How.com.vn is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, 23 people, some anonymous, worked to edit and improve it over time.
The How.com.vn Tech Team also followed the article's instructions and verified that they work.
This article has been viewed 182,533 times.
Here's a quick JavaScript trick to control display settings. All we do is set the display of an element to none, and then use a JavaScript function to toggle the display when a user clicks something else.
Steps
- Wrap the content you want to toggle display within a container.
<div id="content" style="display:block;">This is content.</div>
- Insert JavaScript code to change the display.
<script type="text/javascript">function toggleContent() { // Get the DOM reference var contentId = document.getElementById("content"); // Toggle contentId.style.display == "block" ? contentId.style.display = "none" : contentId.style.display = "block"; }</script>
Advertisement - Use an event handler to trigger the function.
<button onclick="toggleContent()">Toggle</button>
Advertisement
Community Q&A
- QuestionHow do I create CSS animation in JavaScript?A_random_readerCommunity AnswerYou might want to use jQuery animations. More information and documentation is available at api.jquery.com.
Is this article up to date?
⚠️ Disclaimer:
Content from Wiki How English language website. Text is available under the Creative Commons Attribution-Share Alike License; additional terms may apply.
Wiki How does not encourage the violation of any laws, and cannot be responsible for any violations of such laws, should you link to this domain, or use, reproduce, or republish the information contained herein.
- - A few of these subjects are frequently censored by educational, governmental, corporate, parental and other filtering schemes.
- - Some articles may contain names, images, artworks or descriptions of events that some cultures restrict access to
- - Please note: Wiki How does not give you opinion about the law, or advice about medical. If you need specific advice (for example, medical, legal, financial or risk management), please seek a professional who is licensed or knowledgeable in that area.
- - Readers should not judge the importance of topics based on their coverage on Wiki How, nor think a topic is important just because it is the subject of a Wiki article.