I had a script.exit() at the end that I didn’t include in the post above. I had this because I was testing an alternate method below it that I have since removed. I removed the script.exit and the elements gain the color override after the alert appears but only for a second, after which they return to their default white color. Not sure what is going on there.
EDIT: Never mind, I accidentally had uncommented code below this that was causing an error.