// Hide div :
document.getElementById(div_id).style.display = none;
/// Show div :
document.getElementById(div_id).style.display = block;
//Hide
document.getElementById("id").style.display = "none";
//Show
document.getElementById("id").style.display = "block";
//If you have jquery, you can use the following method:
$("#mydiv").hide(); //hides div.
$("#mydiv").show(); //shows div.
//If you don't have jquery...
//search up the following: html how to add jquery
METHOD 1
=================
function myFunction() {
var x = document.getElementById("myDIV");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
METHOD 2
=================
<!--SELECT ELEMENT-->
<div class="form-group row">
<label class="col-md-3 label-control" for="projectinput1"> <b>Group Type</b></label>
<div class="col-md-4 mx-left">
<select id="projectinput7" name="period1" class="form-control round" required="" onchange="select_group(this.value)">
<option value="" selected="">- Select Group Type -</option>
<option value="GROUP-SAVINGS">Cooperative Group Savings</option>
<option value="GROUP-LOANS">Cooperative Group Loans</option>
</select>
</div>
</div>
<style>
.showx{
visibility: visible;
display: block;
}
.hidex{
visibility: hidden;
display: none;
}
</style>
<script>
function select_group(group_type){
var group_type;
//alert(group_type);
//GROUP SAVINGS
if(group_type == 'GROUP-SAVINGS')
{
//show
document.getElementById("payment_period").style.visibility = "visible";
document.getElementById("payment_period").setAttribute("style", "showx");
//hide
document.getElementById("tenor").style.display = "none";
document.getElementById("optional_info").style.display = "none";
}
//GROUP LOANS
if(group_type == 'GROUP-LOANS')
{
//show
document.getElementById("payment_period").style.display = "none";
document.getElementById("amount_payable").style.display = "none";
document.getElementById("optional_info").setAttribute("style", "hidex");
//hide
document.getElementById("tenor").setAttribute("style", "showx");
document.getElementById("optional_info").setAttribute("style", "showx");
}
}
</script>
<td class="post">
<a href="#" onclick="showStuff('answer1', 'text1', this); return false;">Edit</a>
<span id="answer1" style="display: none;">
<textarea rows="10" cols="115"></textarea>
</span>
<span id="text1">Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum</span>
</td>
<script>
function showStuff(id, text, btn) {
document.getElementById(id).style.display = 'block';
// hide the lorem ipsum text
document.getElementById(text).style.display = 'none';
// hide the link
btn.style.display = 'none';
}
</script>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
</head>
<body>
<div id="box" style="background-color: salmon; width: 100px; height: 100px">
Box 1
</div>
<button id="btn">Hide div</button>
<script src="index.js"></script>
</body>
</html>
hide and show divs using javascript