How to order by number?

I think that is a very big problem for every coder since it can destroy every page but does someone know perhaps how to correct it? Someone trieing to order DOM elements by JQuery finds very fast that the algorythm does not really compare to the fullest.

So for example

divArr = $("a:has(.ads)")
function ab() {
        $(".paginate").hide()
        divArr.sort(function(a, b) {
                return $(a).find(".price1").text() > $(b).find(".price1").text() ? 1: -1;
        })
        $(".paginate").append(divArr)
        $(".paginate").fadeIn().slideDown('1032')
}
function ba() {
        $(".paginate").hide()
        divArr.sort(function(b, a) {
                return $(a).find(".price1").text() > $(b).find(".price1").text() ? 1: -1;
        })
        $(".paginate").append(divArr)
        $(".paginate").fadeIn().slideDown('1032')
}

One function is to order ascending and the other descending. But still, they don’t GET ordered by price only, if there are other numbers outside of the .price1 class DOM element.

Some elements get ordered by a string outside of that class. I don’t know why that is. Thx for any help.

I consider that a reason why it is logical to change to a CMS, that already has these functions and also orders them for the whole array that is paginated too.