Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escaped url when setting a css variable with js

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?

like image 669
What What Avatar asked Oct 28 '25 17:10

What What


1 Answers

Add quotes to the path:

window.document.body.style.setProperty("--path", "url('test.png')");
like image 117
Temani Afif Avatar answered Oct 31 '25 08:10

Temani Afif



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!