Answer the question
In order to leave comments, you need to log in
How to run a script on button click?
function sortable(cls, attr) {
var elements = document.querySelectorAll(cls),
len = elements.length,
parent = document.querySelector('.posts-rub'),
arrElements = [];
for(var i = 0; i < len; i++) {
arrElements.push({
dataAttr : elements[i].getAttribute(attr),
el: elements[i]
});
}
arrElements.sort(function(a, b){
return parseInt(a.dataAttr) > parseInt(b.dataAttr) ? 1 : -1;
});
for(var j = 0; j < len; j++) {
parent.appendChild(arrElements[j].el);
}
}
sortable('.cards', 'data-views');
Answer the question
In order to leave comments, you need to log in
Let's say we have a button with Id="LOL"
<button id="lol">
LOL
</button>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question