How to upgrade the filter javascript?

Good afternoon there is such a code filter
$(document).ready(function () {
 var eqEtage;
 var eqPrice;
 var eqSquare;
 $('.filter-item__buttons .button').on('click', function (event) {
event.preventDefault();
 $('.filter-item__buttons .button').removeClass('active');
$(this).addClass('active');
});
 $('#filter-aply').on('click', function () {
 var etage = $('.filter-item__buttons').children('.button.active').data('etg');
 etage = parseFloat(etage); // Squareя

 var squareMin = $("#js-range__metr").data('from');
 squareMin = parseFloat(squareMin);
 var squareMax = $("#js-range__metr").data('to');
 squareMax = parseFloat(squareMax); // Price

 var priceMin = $("#js-range__price").data('from');
 priceMin = parseFloat(priceMin);
 var priceMax = $("#js-range__price").data('to');
 priceMax = parseFloat(priceMax);
 var dataCount = 0;
 var saleItems = $('.sale-item');

 for (var i = 0; i < saleItems.length; i++) {
 var item = saleItems[i];
 var etageLocal = $(item).data('etage');
 etageLocal = parseFloat(etageLocal);
 var price = $(item).data('price');
 price = parseFloat(price);
 var square = $(item).data('square');
 square = parseFloat(square);
 eqPrice = price <= priceMax && price >= priceMin;
 eqEtage = etageLocal == etage;
 eqSquare = square <= squareMax && square >= squareMin;

 if (eqEtage == false || eqPrice == false || eqSquare == false) {
$(item).removeClass('showed');
$(item).removeAttr('data-count');
}

 if (eqPrice == true && eqEtage == true && eqSquare == true) {
$(item).addClass('showed');
dataCount++;
 $(item).attr('data-count', dataCount);
 $('.sale-item__eye').attr('data-position', dataCount);
 // $('.sale-item[data-count="1"]').click();
}
}
});
});


This script is responsible for changing the class on the button
$('.filter-item__buttons .button').on('click', function (event) {
event.preventDefault();
 $('.filter-item__buttons .button').removeClass('active');
$(this).addClass('active');
 });


And as you can see only one button will have the active class
But changed the task and now you can select both buttons
$('.filter-item__buttons .button').on('click', function (event) {
$(this).toggleClass('active');
 });


So the question is how to change the code of the filter ( when you click) what if the length of buttons == 1 ( ie one button ) a script which is below
If the length is greater than 1 ( selected 2 buttons) that eqEtage machine is true because in any case runs
Thanks in advance
April 3rd 20 at 18:38
0 answer

Find more questions by tags JavaScriptjQuery