-3

I want to make a div visible on button click,and i also need the clicked button is invisible when the div is appeared

vishnu reji
  • 193
  • 2
  • 11

6 Answers6

1

To start with you can hide the div initially and then hide show the button and div on button click like this

$(document).ready(function() {
  $("#hide").click(function() {
    $(this).hide();
    $("#div").show();
  });

});
#div {
  display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<p>If you click on the "Hide" button, button will disappear And A div will appear.</p>

<div id="div"> I am a div </div>
<button id="hide">Hide</button>

Read here about jQuery hide() and show()

Sanchit Patiyal
  • 4,910
  • 1
  • 14
  • 31
1

You can use this code,

$('#your_button_id').on('click',function(){
  $('#your_div_id').show();
  $(this).hide();
});
Martin Schneider
  • 3,268
  • 4
  • 19
  • 29
Abhilash Ravindran C K
  • 1,818
  • 2
  • 13
  • 22
1

you can get your answer from this: Make one div visible and another invisible

You can use the display property of style. Intialy set the result section style as

style = "display:none" Then the div will not be visible and there won't be any white space.

Once the search results are being populated change the display property using the java script like

document.getElementById("someObj").style.display = "block" Using java script you can make the div invisible

document.getElementById("someObj").style.display = "none

ryanlee
  • 341
  • 3
  • 9
0
function showDiv() {
    document.getElementById('myId').style.display='block';
    document.getElementById('myButton').style.display='none';
}
0

Modified from the css wc3schools tryit editor site

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
    $("#desc").toggleClass("blue");
    $("#mybutton").toggleClass("blue");
    });
});
</script>
<style>
.blue {
    display: none;
}
</style>
</head>
<body>

<div id="desc" class="blue">
<h1>Heading 1</h1>
<h2>Heading 2</h2>

<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
</div>
<button id="mybutton">Toggle class</button>

</body>
</html>
dskow
  • 924
  • 6
  • 9
0

Using jQuery we can achive this:::

**HTML:**
<div class="divClass">  
    My Div Content shows here  
</div>

<button> Click me </button>

**CSS:**
.divClass {
    display: none
}

**JS:**
$('body').on('click', 'button', function() {
    $(this).hide();
    $('.divClass').show();
});

**Output:** 
https: //jsfiddle.net/cvsraghava/8hg786x9/
Rag ch
  • 76
  • 2