Skip to content Skip to sidebar Skip to footer

Sort List Items From Random Child

UPDATE: As many people refer that the question was not enough clear I'm going to try to explain it better ^_^ thanks for your help and patience! I have a list of around 15 items (t

Solution 1:

try giving your ul an id

<ul id='sorted_list'>

then in javascript you can do:

elementlist = ['A', 'B']
randomelement = Math.floor(Math.random() * elementlist.length)

list = document.getElementById('sorted_list')
listelement = document.createElement('LI')
listelement.textContent(elementlist[randomelement])
list.appentChild(listelement)

combine this with zvonas answer, and you should manage it.

Solution 2:

To help you to get started:

var elems = ['A','B','C','D','E','F'];
var selectedLetter = 'D';
var newOrder = elems.splice(elems.indexOf(selectedLetter)).concat(elems);

Post a Comment for "Sort List Items From Random Child"