$(document).ready(function() {
$("#t1").hide(); // hide table by default
$("#close").hide(); //hide the minus button as well if you only want one button to display at a time
$('#sp1').on('click', function() { //when plus button is clicked
$("#t1").show();
$("#sp1").hide(); //you need to hide the plus button now
$("#close").show(); //and then display the minus button
});
$('#close').on('click', function() {
$("#t1").hide(); //hide table
$("#close").hide(); //hide minus btn
$("#sp1").show(); //show plus button
});
});
$(document).ready(function() {
$("#t2").hide(); // hide table by default
$('#sp2').on('click', function() {
toggleButtons(true);
$("#t2").show();
});
$('#close2').on('click', function() {
toggleButtons(false)
$("#t2").hide();
});
function toggleButtons(show) {
if (show) {
$("#sp2").hide();
$("#close2").show();
} else {
$("#sp2").show();
$("#close2").hide();
}
}
});
<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.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<link href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" rel="stylesheet"/>
<link href="https://pro.fontawesome.com/releases/v5.10.0/css/fontawesome.css" rel="stylesheet"/>
<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></button><button class="table-minus-btn" id="close"><i class="fa fa-minus"></i></button> Child Heading
</th>
</tr>
<tr>
<td colspan="2">
<div class="table1shw">
<table class="table1 table-hover" 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>
<tr>
<th style="background: #eef7fc; text-align: left;" colspan="2">
<button class="table-plus-btn table1" id="sp2"><i class="fa fa-plus"></i></button><button class="table-minus-btn" id="close2"><i class="fa fa-minus"></i></button> Child Heading2
</th>
</tr>
<tr>
<td colspan="2">
<div class="table1shw">
<table class="table1 table-hover" id="t2">
<tr>
<td style="text-align: left; width: 800px;">
Row 3
</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 4
</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>
Hello, I'm having trouble figuring out how to display only one table when I click on the plus button. Right now, both tables are opening simultaneously. I want to show one at a time and close the other when I open a new one. I've successfully implemented this using an accordion before, but I'm struggling here. Can someone please assist me with this issue?