How to add another number to each number of a certain class?
-
How to add a different number to each number of a certain class?
For example, we have:
<span class="current-price">20 000 ₽</span> <div class="second-price-par"> <span class="other-price">10000</span> <span class="other-price">50000</span> </div>
It is necessary to add the number.current-price
to each number.other-price
I tried to get the values like this, but in fact you need to create an array and a loop in PHP, I'm at a loss how to do this.
const regEx = '₽'; let firstPrice = document.querySelector('span.PricesalesPrice').innerHTML; let secondPrice = document.querySelector('.other-price').innerHTML; let nextPrice = firstPrice.replace(regEx, ''); let nextSecondPrice = secondPrice.replace(regEx, '');
JavaScript Anonymous, May 25, 2019 -
document.querySelectorAll('.other-price').forEach(n => {
n.textContent = +n.textContent +
parseInt(document.querySelector('.current-price').textContent.split(' ').join(''));
});Silas James -
Here's another option.
Anonymous
2 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!