S
S
Sergey Sergeev2018-02-09 14:03:56
JavaScript
Sergey Sergeev, 2018-02-09 14:03:56

How to get tag value without nested tag value?

All good afternoon!
We have the following structure:

<span class="price">
  <span class="currencySymbol"></span>
  210.00
</span>

I want to get only the number 210, without the currency sign.
To get the value of the total span, use: Question: how to get a figure without a currency and without frameworks?
document.querySelectorAll('.price');

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Osher, 2018-02-09
@svsergeev

var priceEl = document.querySelector('.price');
var matches = priceEl.textContent.match(/[0-9.]+/);
var price = Number(matches[0]);

console.log(price);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question