0 votes
1 view
in Java by (9.2k points)

Below is the JS code to show a div when clicked on a button:

<script type="text/javascript">

var _hidediv = null;

function showdiv(id) {



    var div = document.getElementById(id);

    div.style.display = 'block';

    _hidediv = function () { div.style.display = 'none'; };



I want to hide it when clicked again and when div should be visible when I click it. Can anyone tell me how to do it?

1 Answer

0 votes
by (19k points)

Below is the HTML code:

<a id="button" href="#">Show/Hide</a>

<div id="item">Item</div>

Check out the below JQuery script: 

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

    $( "#item" ).toggle();


Interested in Java? Check out this Java tutorial by Intellipaat.   

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Dec 30, 2020 in BI by Chris (11.1k points)
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !