article data-id sort

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oll3i
    Contributor
    • Mar 2007
    • 679

    article data-id sort

    I want to sort by article data-id ?
    With jQuery
    How can i do that?
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    what have you tried?

    Comment

    • oll3i
      Contributor
      • Mar 2007
      • 679

      #3
      i have tried

      Code:
      $(document).ready(function () { 
      $('article').sort(function (a, b) {
            var contentA =parseInt( $(a).attr('data-id'));
            var contentB =parseInt( $(b).attr('data-id'));
            return (contentA < contentB) ? -1 : (contentA > contentB) ? 1 : 0;
         })
      });

      Comment

      • oll3i
        Contributor
        • Mar 2007
        • 679

        #4
        Code:
        <section class="offers" id="featured-offers">
        <article id="item-3929173859" class="offer promo-bold" data-id="3929173858" data-location="Nysa">1</article>
        <article id="item-3929173859" class="offer promo-bold" data-id="3929173857" data-location="Nysa">2</article>
        <article id="item-3929173859" class="offer promo-bold" data-id="3929173856" data-location="Nysa">3</article>
        <article id="item-3929173859" class="offer promo-bold" data-id="3929173859" data-location="Nysa">4</article>
        </section>
        i want to sort by data-id

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          in jQuery the data-id is accessed through the data() method. i.e.
          Code:
          $(this).data("id")
          besides that, there is no sorting of elements in the jQuery library. however a quick google search came up with http://james.padolsey.com/javascript...s-with-jquery/

          Comment

          Working...