Mike23,
var elem = document.querySelector('.elem');
var buttonPlus = document.querySelector('.button_plus');
var buttonMinus = document.querySelector('.button_minus');
var num = 0, max = 5, min = 0;
//var num = +elem.innerHTML;
buttonPlus.addEventListener('click', addElem);
buttonMinus.addEventListener('click', removeElem);
function addElem() {
num = Math.min(++num, max)
elem.innerHTML = num;
}
function removeElem() {
num = Math.max(--num, min)
elem.innerHTML = num;
}
|