473,386 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

article data-id sort

oll3i
679 512MB
I want to sort by article data-id ?
With jQuery
How can i do that?
Feb 12 '14 #1
4 1434
Dormilich
8,658 Expert Mod 8TB
what have you tried?
Feb 12 '14 #2
oll3i
679 512MB
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
679 512MB
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
8,658 Expert Mod 8TB
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

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

Similar topics

19
by: David | last post by:
Hi all, A while back I asked how to sort an array of strings which would have numerals and I wanted to put them in sequential numerical order. For example: myArray = "file1"; myArray =...
0
by: Frank King | last post by:
Hi, I am using CArray and quick sort funciton to sort an array of double type of data points. I found an article in MSDN HOWTO: Quick Sorting Using MFC CArray-Derived Classes ID: Q216858 ...
7
by: DC Gringo | last post by:
I have a datagrid that won't sort. The event handler is firing and return label text, just not the sort. Here's my Sub Page_Load and Sub DataGrid1_SortCommand: -------------------- Private...
3
by: Alexander Widera | last post by:
Hi, I have a problem with this code ... (see below) ... I want to sort an instance of MyList ... by MyData.Shortname ... Shortname is of the type string.... how can I sort the entries? Thank...
14
by: william.hooper | last post by:
There is a longer article about this subject here: http://www.codeproject.com/useritems/SortedList_Bug.asp See the main article and the reply thread started by Robert Rohde. Alternatively look...
31
by: Lane Straatman | last post by:
void s_sort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)) { size_t bytes; unsigned char *array, *after, *i, *j, *k, *p1, *p2, *end, swap; array = base;...
0
by: JosAH | last post by:
Greetings, I was asked to write a Tip Of the Week; so here goes: a lot of topics are started here in this forum (and a lot of other forums too) mentioning a problem about sorting data. ...
0
Seth Schrock
by: Seth Schrock | last post by:
Introduction There have been a few times recently that I have had to make it so that users could easily change the order of records. This comes in handy when planning tasks and you don't...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.