Results 1 to 3 of 3

Thread: Random Content Order applied to <tr> elements in IE

  1. #1
    Join Date
    Sep 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Random Content Order applied to <tr> elements in IE

    1) Script Title: Random Content Order

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...ntentorder.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

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    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:

    Code:
    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.

  3. #3
    Join Date
    Sep 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Thanks!

    Thank you for the quick reply. That works for both IE and FF!

    Thanks,
    jderoo

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •