У меня возникают проблемы с этим, если я нажимаю кнопку, одна таблица становится скрытой, а другая показана.
Вот ссылка на DEMO
Вот основные биты кода:
<div id="container">
<table id="1" div id="table3">
<div class="table_2col">
<div class="caption">
<ul>
</div><!--/ column 3-->
<div class="clear"></div>
</div><!--/. table_3col-->
<div class="table_4col">
<div class="caption">
Я использую таблицу id = "1" для первой таблицы и таблицы id = "2" для второй, но это, похоже, забирает стиль css.
Css:
a.button{
color: white;
padding: 0.5rem;
border-radius: 5px;
text-decoration: none;
&:hover;
}
a.button:nth-child(1){
background-color: #FA202B;
}
JavaScript:
(function () {
var tables = $("table");
//Grabs all the tables
tables.hide().first().show();
//Hides all the tables except first
$("a.button").on("click", function () {
//Adds eventListner to buttons
tables.hide();
//Hides all the tables
var tableTarget = $(this).data("table");
//Gets data# of button
$("table#" + tableTarget).show();
//Shows the table with an id equal to data attr of the button
})
})();
Я бы установил все таблицы для display:none;
а затем используйте jQuery Toggle Class для добавления переопределяющего "видимого" класса в текущую таблицу.