Показать сообщение отдельно
  #2 (permalink)  
Старый 22.09.2020, 23:56
Аватар для voraa
Профессор
Отправить личное сообщение для voraa Посмотреть профиль Найти все сообщения от voraa
 
Регистрация: 03.02.2020
Сообщений: 2,692

Вот таким должен быть index.js
function mySort() {
  let sorty = document.querySelector('.goods-wrap');
   for (let i = 0; i < sorty.children.length; i++) {
   for(let j = i; j < sorty.children.length; j++){
    if(+sorty[i].getAttribute('data-price') > +sorty.children[j].getAttribute('data-price')) {
     replacedNode = sorty.replaceChild(sorty.children[j], sorty.children[i]);
     insertAfter(replaceNode, sorty.children[i]);
      }
    }
  }
}

function insertAfter(elem, refElem) {
 return refElem.parentNode.insertBefore(elem, refElem.nextSibling);
}

document.addEventListener('DOMContentLoaded', ()=> {
    document.querySelector('.sorted-price').onclick = mySort;
})
Ответить с цитированием