I
I
Igor Lamp2020-04-22 06:18:09
JavaScript
Igor Lamp, 2020-04-22 06:18:09

How to get text from all spans?

There are 4 spans on the page with the same class, and each of them has its own percentage value.

I need to get a value from each and put it preferably in an array, and then check this array through the elseif condition, for more or less than I need

. does not exceed. Tried Through .text (), It glues everything together without spaces.

Please tell me how to write this

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pashenka, 2020-04-22
@lampd

You would at least bring your futile attempts or markup as a last resort.
Well:

var arr = [];
document.querySelectorAll('.classname').forEach(function(item) {
    arr.push(item.textContent);
});
console.log(arr);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question