JSFiddle - React, Tailwind, and code Playground

by alnitak

HTML

<div id="id_123456_7890123"> .. </div>
<div id="id_123456_1120092"> .. </div>
<div id="id_555222_1200192"> .. </div>
<div id="id_123456_9882311"> .. </div>

JavaScript

function find_by_id(el, re, s) {
    
    s = s || [];
    if (el.tagName === 'DIV' && re.exec(el.id) !== null) {
        s.push(el);
    }

    var c = el.firstChild;
    while (c) {
        find_by_id(c, re, s);
        c = c.nextSibling;
    }
    
    return s;
}

var d = find_by_id(document.body, /^id_123456_/);
console.log(d);