11

I'm loading a bunch of files as background-image using jQuery and I have this image that will simply not load. The browser does not throw any error.

I know the problem is that the file name contain parentheses (), but I've tried all sorts of things and nothing works. This is not a duplicate from this question as the solution there does not work.

This is the URL of the file

http://oceanhotelsimages.com/uploads/200x150_Privilege_Lounge_OBS_05_(1).jpg

I've tried different things in Javascript with no luck.

unescape(str);

encodeURI(str)

Even directly replacing the characters

str.replace("(", "%28");
str.replace(")", "%29");

Even by pure desperation

str.replace("(", "(");
str.replace(")", ")");

Help me StackOverflow, you are my only hope.

Please do not suggest to change the file name. I do not have access to that file.

0

1 Answer 1

26

The solution was easier than I thought. I was missing the quotes when declaring the url of the CSS property.

$(this).css({
    "background-image": "url('" + someString + "')"
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.