plasticboy.de

About the art of building metaphoric solutions to real world problems.

Archive for November 13th, 2009

javascript

My current project involves some jQuery code.
I needed to alternate the background color for a html table with subtables and i wanted to do it in javascript.

So if your table looks something like this, use my Javascript code to color the rows:

<table>
   <tbody class="Alternate">
        <tr><td>I'm a row</td></tr>
        <tr><td><table><tr><td>I'm a subtable for whatever purpose...</td></tr></table></td></tr>
        <tr><td>I'm a row</td></tr>
        <tr><td><table><tr><td>I'm a subtable for whatever purpose...</td></tr></table></td></tr>
        <tr><td>I'm a row</td></tr>
        <tr><td><table><tr><td>I'm a subtable for whatever purpose...</td></tr></table></td></tr>
        <tr><td>I'm a row</td></tr>
   </tbody>
</table>

Here’s the the JavaScript.
It’s a one liner, but i wrapped it for better readability

	//Nice trick to get zebra tables with subtables
	$("tbody.Alternate > tr").filter(function (index) {
                  return index%4==0;
				  }).addClass("Dark");

Finaly the CSS.

.Dark {background-color: green;}
  • 0 Comments
  • Filed under: Programming
  • I’ve seen this video linked on reddit today.
    As some of you know, I am totaly into machine vision these days and this 3d tracing software that imediately caught my attention.

    Think about putting your face into your favorite video game – the term “Headshot” needs to be redefined then.


    Recent Comments

    Links


    Add to Technorati Favorites

    Archives