So I have a weird issue, I am trying to dynamically load images in my theme folder via jquery's css function

$div.css({'background': 'url(' + path + path_to_image + ')'});

where path is the path to my theme and path_to_image is the path to the image within a folder in the theme folder. Anyway it works on some pages, but doesn't work on others.

Inspecting closer, I see on the pages where it works it gets the path to the image ok, just for example it would be path_to_instilation/sites/all/themes/theme_name/image/img.png, but on the pages it doesn't, it quite inexplicably puts an extra thing in there, like it will say path_to_instilation/node/sites/all/themes/theme_name/image/img.png for example. It will throw an unwanted node/ term or a content/ term in the path. What gives? I use an alert to look at the path right before I call the css function, and the path is correct and doesn't have the unwanted terms. But it looks like this is being done automatically. Is there any way around this? This is messing up my whole theme. Please help!

Comments

jaypan’s picture

$div.css({'background': 'url(' + Drupal.settings.basePath + path + path_to_image + ')'});

Contact me to contract me for D7 -> D10/11 migrations.