0
<div id="container" data-price="30.00">30.00</div>
<div id="container" data-price="62.00">62.00</div>
<div id="container" data-price="12.00">12.00</div>
<div id="container" data-price="45.00">45.00</div>
<div id="container" data-price="28.00">28.00</div>
function sorterDesc(a, b) {
    return b.getAttribute('data-price') - a.getAttribute('data-price');
};

var sortedDivs = $('#container').toArray().sort(sorterDesc);
$.each(sortedDivs, function(index, value) {
    $('#container').append(value);
});

The above sorting is working in chrome and IE but not working in firefox. what was wrong in this code?

rrk
  • 15,677
  • 4
  • 29
  • 45

1 Answers1

0

this code now run in all browser.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-beta1/jquery.min.js"></script>
   
</head>
<body>
    <div id="container" data-price="30.00">30.00</div>
    <div id="container" data-price="62.00">62.00</div>
    <div id="container" data-price="12.00">12.00</div>
    <div id="container" data-price="45.00">45.00</div>
    <div id="container" data-price="28.00">28.00</div>
    <div id="sortedDiv"></div>
</body>
</html>

<script type="text/javascript">
    function sorterDesc(a, b) {
        return b.getAttribute('data-price') - a.getAttribute('data-price');
    };

    var sortedDivs = $('[id*=container]').toArray().sort(sorterDesc);
    $.each(sortedDivs, function (index, value) {
        $('#sortedDiv').append(value);
    });
</script>
Sheikh imran
  • 1
  • 1
  • 1