If the newprice initially contains the minimum price, which is also a step of change, then it is better to write this value in the data-attribute of the common container (even though through PHP, even with JavaScript). Despite the greater amount of code, it will be easier - especially if there are several blocks on the page.
An example of the code that demonstrates this:
// при готовности DOM уже можем работать с элементами document.addEventListener('DOMContentLoaded', () => { // добавляем всем блокам дата-атрибут с мин.ценой let elems = document.querySelectorAll('.price-block .newprice'); for (let price of elems) price.parentElement.dataset.minPrice = price.textContent; // вешаем обработчики клика elems = document.querySelectorAll('.price-block input[type="button"]'); for (let btn of elems) btn.addEventListener('click', onPriceBtnClick); }); // обработчик клика по кнопкам function onPriceBtnClick(e) { let parent = this.parentElement, priceEl = parent.querySelector('.newprice'), price = +priceEl.textContent; // увеличиваем/уменьшаем на величину мин.цены; присваиваем бОльшую из новой цены, и минимальной price += (this.value === 'plus' ? 1 : -1) * parent.dataset.minPrice; priceEl.textContent = Math.max(price, parent.dataset.minPrice); }
.price-block, .price-block > input { display: inline-block; padding: 8px; margin: 4px; font: 16px sans-serif; text-align: center; border: 1px solid #ccc; } .newprice { font-size: 2em; } .price-block > input { min-width: 70px; } .price-block > input[value="minus"] { background: #ebb; } .price-block > input[value="plus"] { background: #add; }
<div class="price-block"> <div class="newprice m_l">33</div> <input type="button" value="minus"> <input type="button" value="plus"> </div> <div class="price-block"> <div class="newprice m_l">42</div> <input type="button" value="minus"> <input type="button" value="plus"> </div>