I have a page where I can’t use <script></script>
and I have to place inline JS within the HTML.
I’m having trouble finding a triple quotation to change the css background-image
URL via JS where I’m already using single and double quotation marks e.g.
<div onmouseover='document.getElementById("anotherDiv").style.backgroundImage = "url("https://www.test.com/image.jpg")";"></div>
where I need a triple quotation mark to wrap:
url("walrus-assets.s3.amazonaws.com/img/20-test-1.jpg")
Any thoughts?
2
Answers
You don’t need to add quotation for url(), do this
Here is a snippet but as the others say, prefer a css and create a listener in the script tags to change the style like in the second snippet or in the third snippet if the script is in the head tags.
Second snippet :
If your script is declared inside the head section, use this third snippet. Therefore you wait that the content is loaded before to assign the ‘divs’ tags and the listener :