4

im trying to set a css custom property with js. The name of the property should be "--path" and the value should be "url(test.png)".

My code looks like this:

window.document.body.style.setProperty("--path", "url(test.png)");

My problem is that now the value of --path is "url(test\.png)". How can i prevent the escaping of this dot?

1
  • Using 'test.png' in single quotes will do the trick. Commented Dec 13, 2019 at 14:56

1 Answer 1

4

Add quotes to the path:

window.document.body.style.setProperty("--path", "url('test.png')");

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.