if (i < currentId){
$el.addClass('cost__elem--success')
}
$el.removeClass('cost__elem--success')
$('.cost__elem').eq(currentIndex - 1).addClass('cost__elem--success');
function calculator() {
var currentIndex = 0,
items = $('.cost__track div'),
itemAmt = items.length,
btnprev = $('.cost__btn-prev'),
btnnext = $('.cost__btn-next');
function cycleItems() {
var item = $('.cost__track div').eq(currentIndex);
items.hide().removeClass('active');;
item.css('display','inline-block').addClass('cost__item--active');
}
btnnext.click(function() {
currentIndex += 1;
if (currentIndex > itemAmt - 1) {
currentIndex = itemAmt - 1;
}
$('.cost__elem').eq(currentIndex - 1).addClass('cost__elem--success');
cycleItems();
checkBtns();
});
btnprev.click(function() {
currentIndex -= 1;
if (currentIndex < 0) {
currentIndex = 0;
}
cycleItems();
checkBtns();
});
const checkBtns = () => {
btnprev.prop('disabled', currentIndex === 0);
btnnext.prop('disabled', currentIndex === itemAmt-1);
}
checkBtns();
}
calculator();
function calculator() {
var currentIndex = 0,
items = $('.cost__track div'),
itemAmt = items.length,
btnprev = $('.cost__btn-prev'),
btnnext = $('.cost__btn-next');
function cycleItems() {
var item = $('.cost__track div').eq(currentIndex);
items.hide().removeClass('active');;
item.css('display','inline-block').addClass('cost__item--active');
}
btnnext.click(function() {
currentIndex += 1;
if (currentIndex > itemAmt - 1) {
currentIndex = itemAmt - 1;
}
cycleItems();
checkBtns();
count(currentIndex);
});
btnprev.click(function() {
currentIndex -= 1;
if (currentIndex < 0) {
currentIndex = 0;
}
cycleItems();
checkBtns();
count(currentIndex);
});
const checkBtns = () => {
btnprev.prop('disabled', currentIndex === 0);
btnnext.prop('disabled', currentIndex === itemAmt-1);
}
checkBtns();
console.log(currentIndex);
function count(currentId){
const elems = Array.from(document.querySelectorAll('.cost__elem'));
const randomItemId = document.querySelector('.cost__item--active').dataset.count;
console.log(currentId);
for (let i = 0; i < elems.length; i++) {
if (i < currentId) {
elems[i].classList.add('cost__elem--success');
} else {
return;
}
}
}
}
calculator();
const response = await fetch(url, {...})
Ранее это константа уже была объявлена из хука стейта
const [response, setResponse] = useState();
Не забудьте передать дефолтное значение в стейт