Looking for a script that places a class on every other div.
I have a row of divs and need to place class=left on one div, then class=right on the following and so on.
Any help would be great.
Looking for a script that places a class on every other div.
I have a row of divs and need to place class=left on one div, then class=right on the following and so on.
Any help would be great.
Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title></title> <style type="text/css"> /*<![CDATA[*/ .left { background-Color:red; } .right { background-Color:green; } /*]]>*/ </style> <script type="text/javascript"> /*<![CDATA[*/ function Cls(id,c1,c2){ var ds=document.getElementById(id).getElementsByTagName('DIV'); for (var z0=0;z0<ds.length;z0++){ ds[z0].className=z0%2==0?c1:c2; } } /*]]>*/ </script> </head> <body onload="Cls('tst','left','right');"> <div id="tst" > <div>1</div> <div>2</div> <div>3</div> <div>4</div> </div> </body> </html>
Vic
God Loves You and will never love you less.
http://www.vicsjavascripts.org/Home.htm
If my post has been useful please donate to http://www.operationsmile.org.uk/
zbphill (09-22-2009)
Bookmarks