JSFiddle - React, Tailwind, and code Playground
by mauricederegt
HTML
<div id="posts">
<div id="post-1">post 1</div>
</div>
JavaScript
function getElementsByIdStartsWith(container, selectorTag, prefix) {
var items = [];
var myPosts = document.getElementById(container).getElementsByTagName(selectorTag);
for (var i = 0; i < myPosts.length; i++) {
//omitting undefined null check for brevity
if (myPosts[i].id.lastIndexOf(prefix, 0) === 0) {
items.push(myPosts[i]);
}
}
return items;
}
var postedOnes = getElementsById('[id^="poll-"]');
alert(postedOnes);