Jump to content

Recommended Posts

Hello.

I have a loop that creates a table from mysql data:

[code]echo '<table border="1" bordercolor="#CFCFCF" align="center">';// a new table for every user...[/code]

I have a javascript function that turns this table into a striped table:

[code]<script language="javascript"><!--
function zebraTable() {
    // get the table
    var t = document.getElementById('zebra');

    // set the class name
    var theClass = "evenRow";

    // get a collection of rows
    var rCol = t.rows;

    // declare the counter
    var rowNum = 0;

    // loop through each row
    for (var i = 0; i < rCol.length; i++) {
        // apply the class name
        if (i % 2 == 0) rCol[i].className = theClass;
    }
}

onload = zebraTable;

--></script>[/code]

This javascrpit will inspect the ID of the table and if it's "zebra" it will stripe it.

All is well untill i want to have two or more tables in one page.

I can't name all of them "zebra" because it will only stripe the first table.

How do i go around this?
Link to comment
https://forums.phpfreaks.com/topic/15787-two-css-zebra-table-created-from-loop/
Share on other sites

Since this isn't a php question and the solution I'll point you to is a CSS solution not javascript, I'll move this to the CSS forum after posting the link to what is likely the best solution:

http://www.alistapart.com/articles/zebratables
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.