How to hide div element by default and show it on click using JavaScript and Bootstrap ? Last Updated : 29 Jul, 2024 Comments Improve Suggest changes Like Article Like Report We have to first hide the div and when a user will click the button we need to display that hiden div on the screen. It is helpul for creating any type of form. There are two methods to solve this problem which are discussed below: Table of Content Using .show() methodUsing .toggle() methodApproach 1: Using .show() methodSet display: none property of the div that needs to be displayed.Use the .show() method to display the div element.Example: This example implements the above approach. HTML <!DOCTYPE html> <html lang="en"> <head> <style> #div { display: none; background: green; height: 100px; width: 200px; color: white; } </style> <link rel="stylesheet" href= "https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"> </script> </head> <body> <h1 style="color:green;"> GeeksforGeeks </h1> <p id="GFG_UP"></p> <div id="div"> This is Div box. </div> <br> <button onClick="GFG_Fun()"> click here </button> <br> <p id="GFG_DOWN" style="color: green;"></p> <script> $('#GFG_UP').text( `Click on button to toggle the DIV Box using Bootstrap.`); function show(divId) { $("#" + divId).show(); } function GFG_Fun() { show('div'); $('#GFG_DOWN').text("DIV Box is visible."); } </script> </body> </html> Output:How to hide div element by default and show it on click using JavaScript and Bootstrap ?Approach 2: Using .toggle() methodSet display: none property of the div that needs to be displayed.Use .toggle() method to display the Div. However, this method can be used to again hide the div.Example: This example implements the above approach. html <!DOCTYPE html> <html lang="en"> <head> <style> #div { display: none; background: green; height: 100px; width: 200px; color: white; } </style> <link rel="stylesheet" href= "https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"> </script> </head> <body> <h1 style="color:green;"> GeeksforGeeks </h1> <p id="GFG_UP"> </p> <div id="div"> This is Div box. </div> <br> <button onClick="GFG_Fun()"> click here </button> <br> <p id="GFG_DOWN" style="color: green;"> </p> <script> $('#GFG_UP').text( `Click on button to toggle the DIV Box using Bootstrap.`); function toggler(divId) { $("#" + divId).toggle(); } function GFG_Fun() { toggler('div'); $('#GFG_DOWN').text("DIV Box is toggling."); } </script> </body> </html> Output:How to hide div element by default and show it on click using JavaScript and Bootstrap ? Comment More infoAdvertise with us Next Article How to hide div element by default and show it on click using JavaScript and Bootstrap ? P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies Bootstrap JavaScript-Questions Bootstrap-Questions +1 More Similar Reads How to Toggle between Hiding and Showing an Element using JavaScript ? Toggle between hiding and showing an element using JavaScript provides the feature of efficient space usage by allowing users to hide content sections they may not need to minimize distractions, leading to a cleaner and more organized layout. Syntaxif (paragraph.style.display === 'none') { paragraph 3 min read How to Show and Hide div elements using radio buttons? In this article, we will see how we can show and hide div elements by clicking on the radio buttons. There are different methods available in jQuery to accomplish this task as listed below: Table of Content Using the hide() and show() methodsUsing the css() methodUsing the hide() and show() methodsT 3 min read How to Show and Hide div elements using Checkboxes ? In order to display data/content of a specific element by selecting the particular checkbox in jQuery we can use the toggle() method. The toggle() method is used to check the visibility of selected elements to toggle between hide() and show() for the selected elements. Syntax: $(selector).toggle(spe 4 min read How to hide/show an image on button click using jQuery ? In this article, we will see how we can hide or show any particular image in jQuery when a button gets clicked. This is quite easy to do with some lines of jQuery code. Before we jump to the topic, let's know which methods of jQuery will be used for this. So there is a method called show() and anoth 3 min read How to add bootstrap toggle-switch using JavaScript ? Bootstrap toggle-switch is a simple component used for activating one of the two given options. Commonly used as an on/off button. The CSS framework is a library that allows for easier, more standards-compliant web design using the Cascading Style Sheets language. Bootstrap 4 is one such widely used 2 min read How to create a collapsible section using CSS and JavaScript ? Collapsible sections are sections of content that can shrink and expand by clicking on them. They are a popular way to organize content in such a manner that the user will be able to see the content of a section only if he wishes. We will learn how to create a simple collapsible section using CSS an 3 min read How to add and remove input fields dynamically using jQuery with Bootstrap ? In this article, we will learn how to add and remove input fields dynamically using jQuery with Bootstrap. The input fields will be added and removed from the HTML document dynamically using jQuery.In this process, we will use the following multiple functions.Click() Method: Used to attach the click 3 min read How to hide element on small devices in Twitter Bootstrap ? Twitter Bootstrap makes extensive use of specific classes to achieve all the various kinds of functionalities.To hide elements on any arbitrary screen size, you can make use of a specific Bootstrap .d-none class.For small screen sizes, you can modify it to use .d-sm-none classFor extra small screen 2 min read How to add a tooltip to a div using JavaScript? Adding tooltip to div element displays a pop-up, whenever the mouse hovers over div. Syntax: html < div title = "" > </div> <script> $(document).ready(function() { $('[data-toggle="tooltip"]').tooltip(); }); </script> Tooltip Methods: .tooltip("show"): It 2 min read How to always show first two rows in dynamic collapse using Bootstrap ? Bootstrap is an open-source front-end CSS framework used widely for the development of interactive websites. Bootstrap with HTML and JavaScript adds interactivity to the user interface. jQuery is a JS library used for the manipulation of HTML DOM, event handling, CSS animations, and Ajax. jQuery is 6 min read Like