How can I find the minimum number and output it inside an html tag in JS?
-
How to find the meanings of all .price and output the number to .min-sum using Javascript?
<div class="parent"> <span>Минимальная стоимость: <b class="min-sum"></b></span> <div сдфыы="product"> <h2>Товар 1</h2> <b class="price">100 ₽</b> </div> <div class="product"> <h2>Товар 2</h2> <b class="price">200 ₽</b> </div> <div class="product"> <h2>Товар 3</h2> <b class="price">3000 ₽</b> </div>
Here's what I tried, then, in fact, you need to remove the ruble symbol, and somehow compare prices, but I don't know how to do it.
function priceObjects(index) { const calc = document.querySelectorAll('.price'); for priceObject of priceObjects { let priceText = priceObject.textContent; } document.querySelector('.min-sum').textContent('.price'); }
JavaScript Anonymous, Feb 17, 2020 -
document.querySelector('.min-sum').innerText = Math.min(...Array
.from(document.querySelectorAll('.price'))
.map(n => parseFloat(n.innerText))
);Anonymous
1 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!