-1
<button class="my_btn btn-success">Hide and Show</button></p>
<h1 id="hol">Hello World</h1>



$(".my_btn").on('click', function(event) {
    $("#hol").hide();
});

How to make the same button hide and show the hol block? plz help, i am beginning developer)

Rasul Bek
  • 3
  • 3

2 Answers2

0

use toggle to switch between hide and show

Bilal Hussain
  • 572
  • 6
  • 14
0

You can use jQuery's .toggle() that will display or hide the matched elements:

$(".my_btn").on('click', function(event) {
    $("#hol").toggle();
    // you can set the specific text for the button as well
    $(this).text($(this).text() == 'Show' ? 'Hide' : 'Show');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button class="my_btn btn-success">Hide</button></p>
<h1 id="hol">Hello World</h1>
Mamun
  • 66,969
  • 9
  • 47
  • 59