Looking to dynamically change the background image of an element based on specific strings in the URL. Rather than changing it for each individual term like "Site1", I want to be able to target multiple words. Here's what I've tried:
var urlstring = new Array( "Site1", "Site2", "Site3" ); //Change background if any of these words are in the URL
var imageUrl ="Path to image";
if(window.location.href.indexOf(urlstring) > -1) {
$('#myelement').css('background-image', 'url(' + imageUrl + ')');
}
I realize this may seem amateurish to some, but any expert assistance would be greatly appreciated (there are more similar tasks that need addressing...)