---
title: "Show, Hide and Toggle effects in JavaScript"  
description: "Show, Hide and Toggle effects in JavaScript"  
author: "Anonymous User"  
published: 2021-07-20  
updated: 2023-11-28  
canonical: https://www.mindstick.com/forum/156565/show-hide-and-toggle-effects-in-javascript  
category: "javascript"  
tags: ["javascript"]  
reading_time: 2 minutes  

---

# Show, Hide and Toggle effects in JavaScript

What is the [difference](https://www.mindstick.com/articles/157114/good-news-or-bad-news-and-the-difference-is) between show , hide and [toggle](https://www.mindstick.com/forum/12682/jquery-toggle-if-statement) effects in [JavaScript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript)?

## Replies

### Reply by Aryan Kumar

To show, hide, and toggle elements in JavaScript, you can manipulate the **style** property of the HTML elements or use a library like jQuery for simplified animations. Here's an example using both plain JavaScript and jQuery:

### Plain JavaScript:

```plaintext
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Show, Hide, Toggle in JavaScript</title>
  <style>
    .hidden {
      display: none;
    }
  </style>
</head>
<body>

  <button onclick="showElement()">Show Element</button>
  <button onclick="hideElement()">Hide Element</button>
  <button onclick="toggleElement()">Toggle Element</button>

  <div id="myElement" class="hidden">
    This is the element to show, hide, and toggle.
  </div>

  <script>
    function showElement() {
      var element = document.getElementById("myElement");
      element.style.display = "block";
    }

    function hideElement() {
      var element = document.getElementById("myElement");
      element.style.display = "none";
    }

    function toggleElement() {
      var element = document.getElementById("myElement");
      if (element.style.display === "none") {
        element.style.display = "block";
      } else {
        element.style.display = "none";
      }
    }
  </script>

</body>
</html>
```

### jQuery:

```plaintext
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Show, Hide, Toggle with jQuery</title>
  <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
</head>
<body>

  <button onclick="showElement()">Show Element</button>
  <button onclick="hideElement()">Hide Element</button>
  <button onclick="toggleElement()">Toggle Element</button>

  <div id="myElement" style="display: none;">
    This is the element to show, hide, and toggle.
  </div>

  <script>
    function showElement() {
      $("#myElement").show();
    }

    function hideElement() {
      $("#myElement").hide();
    }

    function toggleElement() {
      $("#myElement").toggle();
    }
  </script>

</body>
</html>
```

In the examples above:

- The **display** property of the element is modified directly using JavaScript.
- In jQuery, the **show()**, **hide()**, and **toggle()** methods are used to achieve the same effects.

Choose the method that best fits your project requirements and coding style.


---

Original Source: https://www.mindstick.com/forum/156565/show-hide-and-toggle-effects-in-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
