I’m making a js function for a Chrome extension that replaces content in the Facebook newsfeed. Each post has the class uiUnifiedStory uiStreamStory genericStreamStory aid_1719315288 uiListItem uiListLight uiListVerticalItemBorder where aid always changes.
If I want to get all the classes, I can’t just use aid_*.
How can I get all of the li elements that match the class uiUnifiedStory uiStreamStory genericStreamStory aid_* uiListItem uiListLight uiListVerticalItemBorder where aid can be anything.
There are many libraries that allow selection by wildcard, however you can do it manually by:
Note that getElementsByClassName returns a live NodeList, but result will be a native Array (as will whatever is returned by the various library implementations of getElementsByClassName).
You can also use querySelectorAll, which I think is more widely supported than getElementsByClassName.
Edit
So you tried:
Ooops, elements is a NodeList, assigning to its innerHTML property either does nothing useful or throws an error. Likely you meant to set the property of the current member of the NodeList:
Note that you can edit your question if you have something to add.