jquery - Reorder li's by time order of time within the li in JavaScript -


I have some sales data that has been loaded in the UL by ajax with the ID of ajax INSER. Unfortunately, these are not in the order of the time of Lee. How do I create a JavaScript function to sort in the order of time of the time taken in the transit time period? I would prefer it as a function which I can add after each new lease, so it takes all Lee's account in the list and re-locates according to them according to time.

  & lt; Ul id = "ajaxinner" & gt; & Lt; Li & gt; & Lt; Span class = "transit time" & gt; 10: 13 - & lt; / Span & gt; & Lt; Span class = "transit amount" & gt; £ 444 & lt; / Span & gt; & Lt; Br> & Lt; IMG src = Image / Orange marker .01 "square =" MapMarker "> Span class =" Transit City "> Stoke-on-Trent (Stoke-on-Trent, United Kingdom)  
  • 10, 08 - a £ 56 fine & lt; / l & gt; Gt; & lt; br & gt; IMG src = "Picture / Orange marker .01" class = "mapmarker"> Span class = "transit whistle" & gt; Belber (Derbyshire, United Kingdom) & lt
  • Span class = "transacttime"> 10: 15 - & lt; / span & gt; & lt; / li & gt; & lt; li & gt; & lt; span class = "transacttime" Gt; & lt; Span Class = "Transit Amount"> £ 39 & lt; br & gt; & lt; img src = "Image / Orange Marker .01" class = "Map Maker" & gt; Span Class = "Transit City"> Stoke-on-Trent (Stoke-on-Trent, United Kingdom)
  • & lt; span class = "transacttime"> 10: 14 - a £ 459 & lt; Br> & Lt; Img src = "picture / orange marker .01" class = "mapmarker" & gt; Span class = "transit whistle" & gt; Belber (Derbyshire, United Kingdom) & lt; / Span & gt; & Lt; / li & gt; <10 × 16 - & lt; / Span & gt; & Lt; Span class = "transamount" & gt; A £ 1057 & lt; / Span & gt; & Lt; Br> & Lt; IMG src = "gtc: suffix =" "& gt; Images / Orange marker .01" class = "mapmarker" & gt; Span class = "transit whistle" & gt; Scarborough (North Yorkshire, United Kingdom) & lt; / Span & gt; & Lt; / li & gt; & Lt; Li & gt; & Lt; Span class = "transacttime" & gt; 10: 11 - & lt; / Span & gt; & Lt; Span class = "transit amount" & gt; £ 107 & lt; / Span & gt; & Lt; Br> & Lt; img src = "images / orange marker .01" class = "mapmarker" & gt; Span class = "transit whistle" & gt; Scarborough (North Yorkshire, United Kingdom) & lt; / Span & gt; & Lt; / li & gt; & Lt; / Ul & gt;

    I have tried so far:

      // time sequence function sortlist () {var ul = $ ('# ajaxInner'); Var li = ul.children ("li"); Li.detach () type () .; ul.append (Lee); }   

    Although this is not always sorted by the order of time and you get some strange results with the above time that should not be.

    Try this:

      functionortlist () {var ul = $ ('# AjaxInner'); Var li = ul.children ("li"); Li.detach (). Sort (function (a, b) {var date1 = new date (new date) toDateString () + '' + $ (a). Child ('span.transactTime'). Text () .substr (0,5) ) var date2 = new date (new date). ToDateString () + '' + $ (b). child ('span.transactTime'). text (). substr (0,5)) var result = (date 1 & lt; date2)? -1: (date1 & gt; date2)? 1: 0 return result;}); ul.append (Lee); }   



  • Comments

    Popular posts from this blog

    Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

    multithreading - PhantomJS-Node in a for Loop -

    c++ - MATLAB .m file to .mex file using Matlab Compiler -