if (sumupVideo !== null) {
sumupVideo.onclick = function() {
this.classList.add('sumup__video-wrap--active')
}
document.body.onclick = function (e) {
if(e.target != sumupVideo) {
sumupVideo.classList.remove('sumup__video-wrap--active')
}
}
}
<div class="appartments-item__room">1</div>
let btn = document.querySelector('.sorting__room');
let toggle = false;
btn.addEventListener('click', function(){
let items = document.querySelectorAll('.appartments-item');
let parent = document.querySelector('.appartments');
let SortElements = new Object();
items.forEach(function(item, indx){
let itemValue = item.querySelector('.appartments-item__room');
SortElements[itemValue] = {'element': item, 'index': indx} ;
});
let keys = Object.keys(SortElements);
function compareNumeric1(a, b) {
if (a < b) return 1;
if (a > b) return -1;
}
function compareNumeric2(a, b) {
if (a > b) return 1;
if (a < b) return -1;
}
if(toggle === false){
keys.sort(compareNumeric1);
toggle = !toggle;
} else {
keys.sort(compareNumeric2);
toggle = !toggle;
}
keys.map(function(key, indx){
parent.insertAdjacentElement('beforeend', SortElements[key]['element']);
SortElements[key]['index'] = indx;
});
return toggle;
}, toggle);