15 lines
No EOL
540 B
JavaScript
15 lines
No EOL
540 B
JavaScript
document.getElementById('sort-select').addEventListener('change', function () {
|
|
const sortValue = this.value
|
|
const $films = [...document.querySelectorAll('.film')]
|
|
console.log('$films', $films)
|
|
$films.sort((a, b) => {
|
|
console.log('a', a)
|
|
const aVal = a.dataset[sortValue]
|
|
const bVal = b.dataset[sortValue]
|
|
return aVal < bVal ? -1 : 1
|
|
})
|
|
document.getElementById('films').innerHTML = ''
|
|
$films.forEach($film => {
|
|
document.getElementById('films').appendChild($film)
|
|
})
|
|
}) |