const selectors = {
wrapper: '.numberQut',
input: '.qut',
minus: '.minusQus',
plus: '.plusQus',
};
const limits = {
min: 1,
max: 5,
};
const updateValue = (el, change = 0) =>
el.value = Math.min(limits.max, Math.max(limits.min, (parseInt(el.value) || 0) + change));
document.addEventListener('click', ({ target: t }) => {
const change = +t.matches(selectors.plus) || -t.matches(selectors.minus);
if (change) {
updateValue(t.closest(selectors.wrapper).querySelector(selectors.input), change);
}
});
document.addEventListener('input', ({ target: t }) => {
if (t.matches(selectors.input)) {
updateValue(t);
}
});