5

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

2 Answers2

16

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

Robin Zigmond
  • 17,805
  • 2
  • 23
  • 34
0

you can use:

document.querySelectorAll("[class$=sarasa]")