the problem I’m facing is that I get a image URL from an input tag then storing it in a let then I create a li tag with an image tag in it. I put imageURL
variable in the src
but the image tag removes the slashes from the variable
JavaScript
x
20
20
1
function addMovie(title, imageURL, rating){
2
const li = document.createElement("li")
3
const ul = document.getElementById("movie-list")
4
li.className = "movie-element"
5
li.innerHTML = `
6
<div class="movie-element__image>
7
<img src="${imageURL}" alt="${title}" id="img" height="100" width = "100">
8
</div>
9
<div class="movie-elements__info">
10
<h2>
11
${title}
12
</h2>
13
<p>
14
${rating}/5 rating
15
</p>
16
</div>
17
`
18
ul.append(li);
19
}
20
Advertisement
Answer
Note that has special meaning. So you need to use
\
instead of like this:
JavaScript
1
2
1
addMovie("test", "images\test\test.jpg" , 12)
2
JavaScript
1
21
21
1
function addMovie(title, imageURL, rating) {
2
const li = document.createElement("li")
3
const ul = document.getElementById("movie-list")
4
li.className = "movie-element"
5
li.innerHTML = `
6
<div class="movie-element__image">
7
<img src="${imageURL}" alt="${title}" id="img" height="100" width = "100">
8
</div>
9
<div class="movie-elements__info">
10
<h2>
11
${title}
12
</h2>
13
<p>
14
${rating}/5 rating
15
</p>
16
</div>
17
`
18
ul.append(li);
19
}
20
21
addMovie("test", "images\test\test.jpg" , 12)
JavaScript
1
1
1
<ul id="movie-list"></ul>
Also you forgot "
after movie-element__image
class