Answer the question
In order to leave comments, you need to log in
Why doesn't sorting work?
$(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>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question