<script>
$(document).ready(function(){
document.querySelector('.increase').onclick = inCrease;
document.querySelector('.decrease').onclick = deCrease;
function inCrease(){
let products = document.querySelector('.sorting');
console.log(products);
for (let i = 0; i < products.children.length; i++){
for (let j = i; j < products.children.length; j++){
if (+products.children[i].getAttribute('data-sort') > +products.children[j].getAttribute('data-sort')){
replacedNode = products.replaceChild(products.children[j], products.children[i]);
insertAfter(replacedNode, products.children[i]);
}
}
}
}
function deCrease(){
let products = document.querySelector('.sorting');
console.log(products);
for (let i = 0; i < products.children.length; i++){
for (let j = i; j < products.children.length; j++){
if (+products.children[i].getAttribute('data-sort') < +products.children[j].getAttribute('data-sort')){
replacedNode = products.replaceChild(products.children[j], products.children[i]);
insertAfter(replacedNode, products.children[i]);
}
}
}
}
function insertAfter(elem, refElem){
return refElem.parentNode.insertBefore(elem, refElem.nextSibiling);
}
});
</script>
Написал вот такую сортировку по цене, как обращаться ко всем элементам с селектором "sorting"?Сейчас работает только в первом