Hello all, hope everyone is well. I'm a bit of a JS novice, so I'm hoping someone can help with this...
The site I'm working on uses a CMS (which I have no access to, nor control over the output), and in one section of the site, it outputs divs like this (I've changed the actual ID names for clarity's sake)...
Code:
<div id="generated-div-1">
<p>Blah</p>
</div>
<div id="generated-div-2">
<p>Blah</p>
</div>
<div id="generated-div-3">
<p>Blah</p>
</div>
etc ad infinitum
Now then, I need to be able to check if a div is called 'generated-div-[number]', and I thought the best way to go about this would be to use regex. However, most of my regex experience comes from doing PHP work, and as I said, I'm a bit of a JS novice.
So far, I've got this...
Code:
function checkDiv() {
var divName = /(^generated-div-)+[0-9]{1}$|[1-9]{1}[0-9]{1}$|(100)$/;
if (document.getElementById.match(var divName)) {
document.getElementById(var divName).style.backgroundColor='#cc0000';
}
}
That's a slightly simpler version of what I want it to do (i.e: in the end, I don't want to merely change the BG colour), but I mainly need some help with the regex and 'if' part of things.
Is that waaaaay off the mark? Any help would be appreciated.
Ta