scrimba
Frontend Career Path
Essential JavaScript concepts
Meme Picker
Aside: parentElement
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

AboutCommentsNotes
Aside: parentElement
Expand for more info
index.js
run
preview
console
const container = document.getElementById('container')

const products = [
{
name: 'Ostrich Pillow',
price: '10',
image: 'ostrichpillow.jpg',
id: 'ostrich-pillow'
},
{
name: 'Bacon Bandages',
price: '8',
image: 'bacon-bandage.jpg',
id: 'bacon-bandages'
},
{
name: 'Baby Mop',
price: '20',
image: 'babymop.jpg',
id: 'baby-mop'
}
]

let productsHtml = ``

for (let product of products){
productsHtml += `
<div class="product">
<h3>${product.name}</h3>
<h4> £${product.price}</h4>
<img src="${product.image}">
<button id="${product.id}">Buy Now</button>
</div>
`
}

container.innerHTML = productsHtml

container.addEventListener('click', function(e){
console.log(e.target.id)
})
Console
/index.html
-3:14