I am trying to as the title suggests, randomise the typeface of my h1 titles throughout the site. All of these are assigned an individual ID using php count so they take the format project-title-1, project-title-2 etc.
I have repurposed this code from a similar question I found on here but tried to apply it so it works on multiple elements.
Currently, if I remove the All from querySelector it works on the first element on the page but no others, so the code kind of works but there is a problem somewhere.
Any insight would be greatly appreciated! Cheers
var fonts = ['hauser', 'helvetica', 'times'];
var rand = fonts[Math.floor(Math.random() * fonts.length)];
console.log(rand);
var bodyElement = document.querySelectorAll("[id^='project-title']");
bodyElement.className = rand;
Basic working example here: https://jsfiddle.net/psvu78aq/2/