Reputation: 63
I need to get all innerText of all elements that partially match a given string.
Heres a snippet of the code:
<span class="18794221455sarasa">Some text</span>
The class always ends with 'sarasa' the numbers are dynamic. I want to run it on a chrome extension that's why I need it to be on plain Javascript
Upvotes: 6
Views: 4164
Reputation: 18249
No, you can't use getElementsByClassName
like that.
But you can use querySelectorAll
with a CSS attribute selector:
document.querySelectorAll('[class$="sarasa"]')
will give you a collection of the DOM elements you want.
See an explanation of this selector here
Upvotes: 17