English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I'm a little (not a lot) more than a beginniner at using JavaScript to various things, but I can't figure out a way to randomize a list of elements and get the result to print. I was trying to combine Math.random, an array of the elements i want to randomize, and an iteration with document.write, but I got nowhere. Any suggestions are appreciated.

2006-12-26 15:49:52 · 3 answers · asked by LSN 2 in Computers & Internet Programming & Design

I want the printed result to be the complete list of elements, but with the elements ordered randomly. That's what I was trying to do by iterating document.write.

2006-12-26 17:42:22 · update #1

3 answers

Just used this code to randomize pictures of my puppy!
hrefs.sort(function(){ return Math.round(Math.random()) -0.5})

hrefs was my array.

UPDATE:

you then loop through the array, and writeln the links...

do you need a program to update in place or demand? that's harder but can be done.

2006-12-26 16:16:43 · answer #1 · answered by jake cigar™ is retired 7 · 0 0

i think of you desire to run a definite javascript code every time the website contains aspects with specific instructions and/or ids. Or have this could't be executed. on your first occasion, td { onclick: some javascript } i will propose, you call a js function on onload of the table which does, var d = rfile.getElementsByTagName('td'); for (var t in d) { t.onclick = "some javascript"; } or a replace of that. word: onclick isn't a css sort. its a html ingredient assets. css can in straightforward terms regulate the kind assets of html aspects @fallendownsince2005 Mr. Lund isn't incorrect. he did no longer say javascript won't be in a position for use for customer area scripting, he reported CSS won't be in a position for use. (perhaps he edited it later) @PSP your 'answer' is easily on a distinctive airplane altogether.

2016-11-23 18:58:00 · answer #2 · answered by ? 4 · 0 0

Looks like you were on the right track. At the bottom of this site is code on how to create an alert box with a random quote, you should be able to modify it from there.
http://www.pageresource.com/jscript/jrandom.htm

2006-12-26 16:14:17 · answer #3 · answered by Bryan A 5 · 0 0

fedest.com, questions and answers