JSFiddle - React, Tailwind, and code Playground
HTML
<div>
<div id="Q01">
<p>Some text</p>
</div>
<div id="Q02">
<p>Some text</p>
</div>
<div id="Q03">
<p>Some text</p>
</div>
<div id="R04">
<p>Some text</p>
</div>
<label for="number">Number of DIVs:</label>
<input type="number" name="result" id="number">
</div>
CSS
.red {
color:red;
}
JavaScript
var Q_Num = $('*').filter(function () {
return this.id.match(/Q\d+/);
});
Q_Num.addClass('red');
alert(Q_Num.length);