javascript - How do I sort a <ul> list by datetime? -
i have <ul>
list generated using javascript when page loads (by appending var <li>
tags <ul>
element).
how can make <li>
newest date @ top when page loads?
also, code extremely long (~6000 words) , include outside sources (to google's api), understand how can implement code. here's pseudo-code explain how stuff generated js/html:
- i have
<ul>
element nothing inside tags - i information user's last 5 uploaded videos youtube using google's api, information includes channel name, video title, video id, thumbnail url, , date , time video published @ (a string iso 8601 format).
- next information used make var (which includes html tags , styles) example:
var output = '<li><p>'+videotitle+'</p><p>'+publishedat+'</p>\ <img src="'+videothumbnail+'" height="90px"></li>'
- this code added via 2 functions. 1 gets information localstorage using function called "addusers()" loop grabs key localstorage , uses var , parses through parameter function adds < ul > list. , 2 gets information text field input (upon clicking button well) activates function "adduserlocalstorage()" adds username localstorage, , displays youtube videos on screen well; on refresh gets information addusers() function.
so it'd super easy add publishedat var anywhere wanted in element without hassle. it's more how implement , use sort unordered list , make ordered.
any suggestions welcome usual :)
since using jquery maybe this help? credits bill richards this blog post.
edit: also, might want consider using data attribute sort - in unix time. that's easier , faster sort having parse text.
Comments
Post a Comment