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');
}
window.onliad = function() {
document.getElementById("lol").onclick = sortable (/* Здесь параметры*/)
}
window.onload = function() {
//your code
}