<div>
<button id="prev"><</button>
<span>3</span>
<button id="next">></button>
</div>
<script>
document.querySelector('div').onclick = function(event) {
var maxValue = 5;
if (event.target.id === 'prev') {
var counter = event.target.nextElementSibling;
if (+counter.innerHTML > 0) {
counter.innerHTML--;
}
}
if (event.target.id === 'next') {
var counter = event.target.previousElementSibling;
if (+counter.innerHTML < maxValue) {
counter.innerHTML++;
}
}
}
</script>