Sharing my experience with setting a background image using Javascript. Initially, I tried using two dots like this:
.style.backgroundImage = "url('../images/image00.jpg')"
However, it did not work as expected. So, I removed one dot:
.style.backgroundImage = "url('./images/image00.jpg')"
This time, it worked! I was surprised because in CSS, we typically use two dots to go back in the directory structure. My folder structure looks like this:
- Folder 1
- index.html
- images
- image.jpg
- scripts
- scripts.js
- styles
- styles.css
I find it interesting that only one dot works in Javascript while two dots work in CSS for navigating directories.
Thank you!