By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,722 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

article data-id sort

oll3i
100+
P: 679
I want to sort by article data-id ?
With jQuery
How can i do that?
Feb 12 '14 #1
Share this Question
Share on Google+
4 Replies


Dormilich
Expert Mod 5K+
P: 8,639
what have you tried?
Feb 12 '14 #2

oll3i
100+
P: 679
i have tried

Expand|Select|Wrap|Line Numbers
  1. $(document).ready(function () { 
  2. $('article').sort(function (a, b) {
  3.       var contentA =parseInt( $(a).attr('data-id'));
  4.       var contentB =parseInt( $(b).attr('data-id'));
  5.       return (contentA < contentB) ? -1 : (contentA > contentB) ? 1 : 0;
  6.    })
  7. });
Feb 13 '14 #3

oll3i
100+
P: 679
Expand|Select|Wrap|Line Numbers
  1. <section class="offers" id="featured-offers">
  2. <article id="item-3929173859" class="offer promo-bold" data-id="3929173858" data-location="Nysa">1</article>
  3. <article id="item-3929173859" class="offer promo-bold" data-id="3929173857" data-location="Nysa">2</article>
  4. <article id="item-3929173859" class="offer promo-bold" data-id="3929173856" data-location="Nysa">3</article>
  5. <article id="item-3929173859" class="offer promo-bold" data-id="3929173859" data-location="Nysa">4</article>
  6. </section>
i want to sort by data-id
Feb 13 '14 #4

Dormilich
Expert Mod 5K+
P: 8,639
in jQuery the data-id is accessed through the data() method. i.e.
Expand|Select|Wrap|Line Numbers
  1. $(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/
Feb 13 '14 #5

Post your reply

Sign in to post your reply or Sign up for a free account.