njpma/app/static/js/films.js

15 lines
540 B
JavaScript
Raw Normal View History

2021-10-28 16:19:16 +00:00
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)
})
})