scrimba
Frontend Career Path
Essential JavaScript concepts
Meme Picker
Aside: getElementsByClassName
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

To see this lesson you need to be logged in. Joining Scrimba is free and gives you access to 20+ courses.Sign up
Aside: getElementsByClassName
AboutCommentsNotes
Aside: getElementsByClassName
Expand for more info
index.js
run
preview
console
const container = document.getElementById('container')
const clearBtn = document.getElementById('clear-btn')

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'
}
]

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

container.addEventListener('click', function(e){
document.getElementById(e.target.id).parentElement.classList.add('purchased')
document.getElementById(e.target.id).parentElement.classList.remove('on-offer')
})

clearBtn.addEventListener('click', function(){

})

/*
Challenge:
1. Finish setting up this array of
elements with the "product" class.
2. Iterate over this array and remove
the "purchase" class and add the
"on-offer" class.
*/










Console
/index.html
-4:58