PDA

View Full Version : Random Content Order applied to <tr> elements in IE



jderoo
09-20-2007, 04:18 PM
1) Script Title: Random Content Order

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/randomcontentorder.htm

3) Describe problem: I am trying to apply the random content order class to a <tr> rather than a <div> (please don't flog me, yet, for using a table - my CSS-fu is still rather weak and I'm on a deadline). It works in FireFox as you would expect, but in IE it is just plain blank. I've attached a stripped-down version of the web page that exhibits the problem.

Should this work at all?

Is there a work-around for the problem I am seeing in IE?

Is there another way to do this?

Thank you,
John DeRoo

ddadmin
09-20-2007, 07:34 PM
In IE, apparently dynamically populating the contents of a tr element using .innerHTML isn't allowed. That's why when you try to randomize TR instead of DIV containers, it doesn't work in IE.

One workaround for this in IE seems to be to randomly move the rows around, using table.moveRow(). This method is IE only. With that said, replace the original randomizeContent() function with the below instead:


function randomizeContent(classname){
var contents=randomizeContent.collectElementbyClass(classname)
contents.text.sort(function() {return 0.5 - Math.random();})
var tableref=contents.ref[0].parentNode
for (var i=0; i<contents.ref.length; i++){
if (tableref.moveRow)
tableref.moveRow(0, Math.round(Math.random()*(tableref.rows.length-1)))
else
contents.ref[i].innerHTML=contents.text[i]
contents.ref[i].style.visibility="visible"
}
}



That should do it in getting the script to work on TR elements as well in IE.

jderoo
09-21-2007, 02:14 AM
Thank you for the quick reply. That works for both IE and FF!

Thanks,
jderoo