I have a list of 10 items. I want to show only 3 random elements from the list: ONE element between 1 and 5.......TWO elements between 6 and 10. who can help me in this? thank you very much!
my code now shows all the elements together...
I would like to show something like:
3.
7.
9.
(only 3 elements)
var list = document.getElementById("items"),
newlist = document.getElementById("shuffle");
function shuffle(items)
{
var cached = items.slice(0), temp, i = cached.length, rand;
while(--i)
{
rand = Math.floor(i * Math.random());
temp = cached[rand];
cached[rand] = cached[i];
cached[i] = temp;
}
return cached;
}
function shuffleNodes()
{
var nodes = list.children, i = 0;
nodes = Array.prototype.slice.call(nodes);
nodes = shuffle(nodes);
while(i < nodes.length)
{
list.appendChild(nodes[i]);
++i;
}
}
window.onload = shuffleNodes;
<form id="something">
<div class="classname">
<dl id="items">
<dd>1. item.<br></dd>
<dd>2. item.<br></dd>
<dd>3. item.<br></dd>
<dd>4. item.<br></dd>
<dd>5. item.<br></dd>
<dd>6. item.<br></dd>
<dd>7. item.<br></dd>
<dd>8. item.<br></dd>
<dd>9. item.<br></dd>
<dd>10. item.<br></dd>
</dl>
</div>
</form>