M
M
Maxim K2019-11-21 13:06:18
Google Chrome
Maxim K, 2019-11-21 13:06:18

How to loop through all values ​​in getElementsByClassname and find a string in them?

Hello.
Get a list of elements on a page

var elements = document.getElementsByClassName("txtBlock");

Next, I get the number of elements I go
var countElements = elements.length;
through the array of elements And then everything is plugged (((( , i.e. if you enter countElements[0].InnerText , then I will see the value in the console And how to search through all the elements, find the right one and take its value? tried and through array, forEach - does not go and that's it (((
for(i=0;i<countElements;i++){}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
VeryLongAgoDid, 2019-11-21
@VeryLongAgoDid

var elements = document.getElementsByClassName("txtBlock");
var countElements = elements.length;

for (let i = 0; i < countElements; ++i) {
    console.log( elements[i] );
    if (...) {
        ...
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question