View Full Version : changing 2nd or 3rd link css depending on page

07-24-2009, 08:26 AM
i have a div which has an id in that i have a div which has a class name then i have a table in the second div and in that i have few links (ie. <a href=...</a>)

<div id="nav">
<div class="moduletable_menu">
<table width="100%" cellspacing="1" cellpadding="0" border="0">
<td nowrap="nowrap">
<a class="mainlevel" href="ssssssss">Home</a>
<a class="mainlevel" href="ssssssssd">About</a>
<a class="mainlevel" href="ddddddd">News2</a>
<a class="mainlevel" href="ddddddd">News21</a>
<a class="mainlevel" href="ddddddd">News4</a>
<a class="mainlevel" href="ddddddd">News4</a>

now i want to change the css of the link only on certain pages .

So i was thinking wheteher i could get the current url of the page and if it is the right one then the propertioes of the 2nd or 3rd link change and if it is on another page the 1st link should change

at any time i may require to chnage atleast one link

so i will require either javascript code which if on the right page selects the 2nd or third link to change and on another page the 1st link

How will i achieve this

can anybody please help me

rnd me
07-24-2009, 08:31 AM
css can do it without javascript.

give each link a different class (eg link1), and each body a different class (i used main and other in the example below).

then you can use one stylesheet that has section like this:

.main .link1, .main .link2 { color: black; }
.main .link3 { color: red; }

.other .link1, .main .link3 { color: black; }
.other .link2 { color: red; }

you can define all three pages' style in the same css file, and it works without javascript enabled...

07-24-2009, 11:00 AM
i think that you want to make a 'nav'
i have a project just last month ,can be help just a littel!!!
you may visite to http://www.zhilian100.com.cn for looking 'nav' coding, it made by javascript and CSS
hoping can be help goodluck!!!