I want to add an image from Firebase Storage in each "li" in the code below, but only the first li has an image. There is no defined src on the other img tags. No errors in the console, but the picURL of each picture is logged in the console, but it won't apply to the src
Code:
var postDocRef = db.collection('posts').doc(uid).collection('userPosts')
postDocRef.get().then(snapshot => {
setupPosts(snapshot.docs)
})
const posts = document.querySelector('.posts');
const setupPosts = (data) => {
let html = '';
data.forEach(doc => {
var docRefIDpost = docRef.id
const post = doc.data();
const li = `
<li>
<div class="title">${post.title}</div>
<div class="content">${post.content}</div>
<img class="img">
</li>
`;
var imgRef = db.collection('posts').doc(uid).collection('userPosts');
imgRef.get().then(function(snapshot) {
if (snapshot.docs.length > 0) {
snapshot.docs.forEach(doc => {
const data = doc.data();
const picURL = data.picURL
console.log(picURL)
var img = document.querySelector(".img")
img.src = picURL
})
} else {
console.log("PicURL doesn't exist")
}
})
html += li
})
posts.innerHTML = html;
}
});