//Custom Table Display Script using JQuery
$(document).ready(function(){
$('.table1').on('click',function(){
$('.table1shw').show();
});
});
//Attempted another method to display the table but failed
document.getElementById('sp1').addEventListener("click", function() {
showTable('t1');
});
function showTable(table) {
var tables = ['t1'];
for (var i = 0; i < 4; i++) {
document.getElementById(tables[i]).style.display = "none";
}
document.getElementById(table).style.display = "block";
}
.table-hide{
display: none;
}
<link href="https://pro.fontawesome.com/releases/v5.10.0/css/fontawesome.css" rel="stylesheet"/>
<link href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/libs/jquery/3.4.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div class="col-md-12 col-12 table-responsive">
<div class="form-group">
<div class="col-md-12" style="padding: 10px !important;" align="center">
<div class="form-group">Main heading</div>
</div>
<table class="table table-hover">
<thead class="lbbg3">
<tr>
<td style="width: 800px;">Sub heading 1</td>
<td>Sub heading 2</td>
</tr>
</thead>
<tbody>
<tr>
<th style="background: #eef7fc; text-align: left;" colspan="2"><button class="table-plus-btn table1" id="sp1"><i class="fa fa-plus"></i></div> <button class="table-minus-btn"><i class="fa fa-minus"></button> Child Heading</th>
</tr>
<tr>
<td colspan="2">
<div class="table1shw"> <table class="table1 table-hover table-hide" id="t1"> <tr>
<td style="text-align: left;width: 800px;">
Row 1
</td>
<td style="text-align: center;">
<div class="custom-control custom-radio radio-table">
<a href="#doc"> <input type="radio" id="customRadio50" name="customRadio" class="custom-control-input fcy edu docbtn">
<label class="custom-control-label" for="customRadio50" style="cursor: pointer;" onchange="valueChanged()"></label></a>
</div>
</td>
</tr>
<tr>
<td style="text-align: left;width: 800px;">
Row 2
</td>
<td style="text-align: center;">
<div class="custom-control custom-radio radio-table ">
<input type="radio" id="customRadio51" name="customRadio" class="custom-control-input fcy">
<label class="custom-control-label" for="customRadio51" style="cursor: pointer;"></label>
</div>
</td>
</tr>
</table></div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
Hey there! I'm having trouble displaying the full table when clicking the plus button, and then hiding it when the minus button is clicked. I've tried two different methods but haven't had any success yet. Feeling a bit stuck here - can you point out where I might be going wrong? Your help would be greatly appreciated.