njpma/app/static/js/films.js
2021-10-28 21:49:16 +05:30

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)
})
})