I'm adding a script that adds random background images to pages, like so:
<script type="text/javascript">
var totalCount = 25;
function addBackground()
{
var num = Math.ceil( Math.random() * totalCount );
document.body.background = 'images/'+num+'.png';
document.body.style.backgroundSize = "contain";
}
</script>
The complication is, I now need to only add backgrounds to pages that have a specific class (not an id) added to their html element. (I don't have access to change the way this works).
I've tried using getElementsByClassName, but I seem to keep getting Undefined back. What's the correct way to do this?
Thanks!