I want to make a div visible on button click,and i also need the clicked button is invisible when the div is appeared
Asked
Active
Viewed 879 times
-3
-
You have to regard what you have tried. In this way, the question may be closed. – SaidbakR Dec 14 '17 at 05:42
6 Answers
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>

Sanchit Patiyal
- 4,910
- 1
- 14
- 31
-
-
Glad I helped. DO accept the answer for future reference to others :) – Sanchit Patiyal Dec 14 '17 at 05:55
-
i need to hide entire div including the button and make new div visible on same position of the old div – vishnu reji Dec 14 '17 at 06:00
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
-
-
i need to hide entire div including the button and make new div visible on same position of the old div – vishnu reji Dec 14 '17 at 06:00
-
Then instead of $(this).hide(); you have to give $('#your_div_id_that _to_hide').hide(); – Abhilash Ravindran C K Dec 14 '17 at 06:02
-
-
@vishnureji please could you accept the answer if it is working for you.Thank you. – Abhilash Ravindran C K Dec 14 '17 at 06:11
-
-
Could you please tell me what transistion effect you need. Also tell me to which item you have to apply the effect. – Abhilash Ravindran C K Dec 14 '17 at 06:17
-
-
For that you can refer this link https://www.w3schools.com/jquery/jquery_fade.asp – Abhilash Ravindran C K Dec 14 '17 at 06:22
-
-
You can use http://api.jquery.com/fadein/ link as well. Best of luck. Thank you for accepting answer. – Abhilash Ravindran C K Dec 14 '17 at 06:24
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';
}

Archita Sundaray
- 77
- 1
- 10
-
-
i need to hide entire div including the button and make new div visible on same position of the old div – vishnu reji Dec 14 '17 at 06:00
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