Lets say I've created some code where the user can keep adding numbers to a <ul>
and next to each <li>
is a delete button which can be used to remove said item off the list. The problem is for it to work each item on the list does not only contain a number it also contains some text. Lets just say:
<li>Bag of potatoes - 25kg</li>
is there any way that I can use .innerText on this list item, to then just extract the number 25 (or whatever number happens to be there) so that I can subtract it from the total.
I have tried the following:
const itemText = item.parentElement.innerText;
const itemWeight = itemText.match(/\d/g) || [];
However in this example it returns 2,5 rather than 25. Is there a simple way I can convert the result 2,5 to 25, or is it possible to do this in a more efficient manner?
Thanks