JSFiddle - React, Tailwind, and code Playground
by John Doe
HTML
<p>Задача: при клике добавить / сбросить значение</p>
<p>+ нужно добавить и удалить класс у кнопки</p>
<hr>
<div class="test">Квартира</div>
<input type="text" value='' />
CSS
.test {
display:inline-block;
padding:5px;
cursor:pointer;
border:1px solid #ccc;
border-radius:5px;
}
.active {
background:#ccc;
}
input {
padding:5px;
}
JavaScript
$(".test").click(function () {
$('.test').toggleClass('active');
var text = $(this).text();
$('input').val() == '' ? $('input').val(text) : $('input').val('');
});