Skip to content
the poor coder

Hide/Show on click jquery

Poor Man
Published
Reading time
1 min read

When it comes to hiding or showing a div on click, jQuery is a great tool to do so. To show a div element on click, you can use the .show() method of jQuery. For example, if you have an element with the ID "myDiv", you can use the following code to show it when a button is clicked:

Text

$("#myButton").click(function(){
   $("#myDiv").show();
});

The above code will look for an element with the ID "myButton", and if it is clicked, it will show an element with the ID "myDiv". To hide a div element on click, you can use the .hide() method of jQuery. Again, if you have an element with the ID "myDiv", you can use the following code to hide it when a button is clicked:

Text

$("#myButton").click(function(){
   $("#myDiv").hide();
});

The above code will look for an element with the ID "myButton", and if it is clicked, it will hide an element with the ID "myDiv". If you want to toggle the visibility of an element on click, you can use the .toggle() method of jQuery. Again, if you have an element with the ID "myDiv", you can use the following code to toggle its visibility when a button is clicked:

Text

$("#myButton").click(function(){
   $("#myDiv").toggle();
});

The above code will look for an element with the ID "myButton", and if it is clicked, it will toggle the visibility of an element with the ID "myDiv".

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC