ItSolutionStuff.com

JQuery Toggle Hide Show Div on Click Event Example

By Hardik Savani • July 6, 2023
jQuery

In this example, i will give you simple example of show and hide div on single button click event in jquery. we can toggle show hide div on click event. we can do it jquery toggle element on click example.

I will give you two example that will do it same thing with hide and show div or element by class or id on click event.

In first example we will use jquery toggle() for hide and show div. In second example we will do it manually hide and show div using text. so let's see both example.

Example 1:

<!DOCTYPE html>

<html>

<head>

<title>Jquery Toggle hide show div on click event example - ItSolutionStuff.com</title>

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

<style type="text/css">

.display-none{

display: none;

}

</style>

</head>

<body>

<button>Show</button>

<div id="example" class="display-none">

Example of ItSolutionStuff.com

</div>

<script type="text/javascript">

$("button").click(function(){

$("#example").toggleClass('display-none');

});

</script>

</body>

</html>

Example 2:

<!DOCTYPE html>

<html>

<head>

<title>Jquery Toggle hide show div on click event example - ItSolutionStuff.com</title>

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

</head>

<body>

<button>Show</button>

<div id="example" style="display: none;">

Example of ItSolutionStuff.com

</div>

<script type="text/javascript">

$("button").click(function(){

if ($(this).text() == "Show") {

$("#example").css('display', 'block');

$(this).text('Hide');

}else{

$("#example").css('display', 'none');

$(this).text('Show');

}

});

</script>

</body>

</html>

I hope it can help you...

Tags: jQuery
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Set and Get Custom Attribute Value using JQuery?

Read Now →

How to Get Selected Radio Button Value in JQuery?

Read Now →

How to Get Last Element from Array using JQuery?

Read Now →

How to Split String to Array By Comma using JQuery?

Read Now →

Add Edit Delete Table Row Example using JQuery

Read Now →

How to Disable Browser Back Button using JQuery?

Read Now →

How to Remove Empty or Null Values from Array in JQuery?

Read Now →

How to Remove Duplicate Object from Array in JQuery?

Read Now →

How to Remove Duplicate Value from Array in JQuery?

Read Now →

How to Get the Current URL using JQuery?

Read Now →

How to Remove Query String from URL using JQuery?

Read Now →

Automatically Scroll to Bottom of Div JQuery Example

Read Now →

Check and Uncheck All Checkbox using JQuery Example

Read Now →

How to Allow Only One Checkbox Checked at a Time in JQuery?

Read Now →