I am setting backgrounds dynamically using a jQuery script however the .css function does not seem to be working. Here is the script:
$(document).ready(function () {
$(".VociMenuSportG").each(function () {
var fullHref = $(this).find('a').attr('href');
console.log(fullHref);
var pos = fullHref.indexOf("IDSport=") + 8;
console.log(pos);
var sportNum = fullHref.substr(pos, 3);
console.log(sportNum);
var imageName;
switch (sportNum.toString()) {
case '523':
imageName = "../Images/soccer_ball01.png";
break;
case '468':
imageName = "../Images/soccer_ball01.png";
break;
}
console.log(imageName);
$(this).css('background-image', 'url (' + imageName + ')');
});
});
The script runs through each item (VociMenuSportG), finds the path of the link in the list item and then sets the background image of the list item. The script successfully runs with no errors and using the console.logs I can see the correct path is chosen. But the background-image simply does not set ? I am wondering if I am maybe using the .css function incorrectly somehow ??
EDIT
Tried setting the paths of the images to absolute paths rather than relative ones but still no luck
background-imagepresent in it's styling?$(this).css({ backgroundImage: 'url("'+ imageName +'")' });