JSFiddle - React, Tailwind, and code Playground
HTML
<input id="test1foo" />
<input id="test2foo" />
<input id="testbar" />
JavaScript
String.prototype.endsWith = function(suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
function getInputsThatEndWith(text) {
var result = new Array();
var inputs = document.getElementsByTagName("input");
for(var i=0; i < inputs.length; i++) {
if(inputs[i].id.endsWith(text))
result.push(inputs[i]);
}
return result;
}
console.log(getInputsThatEndWith("foo"))