<button class="btn" data-modal="modal1">Кнопка #1</button>
<button class="btn" data-modal="modal2">Кнопка #2</button>
<button class="btn" data-modal="modal3">Кнопка #3</button>
<div class="button_block" modal="modal1">Блок 1</div>
<div class="button_block" modal="modal2">Блок 2</div>
<div class="button_block" modal="modal3">Блок 3</div>
button {
background: tomato;
outline: 0;
border: 0;
padding: 15px 25px;
display: inline-block;
margin: 10px;
cursor: pointer;
}
.button_block {
display: none;
padding: 50px 0;
text-align: center;
}
.button_block.active {
background: gray;
}
.active {
display: block;
}
$(document).ready(function() {
$('.btn').on('click', function(){
var modal_index = $(this).data('modal');
$(`.button_block[modal="${modal_index}"]`).toggleClass('active')
.siblings()
.removeClass('active');
});
});
This Pen doesn't use any external CSS resources.