Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    New Zealand
    Posts
    127
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Change cell colour onClick?

    Hi there, i know this shouldn't really be that hard but i can't get it.

    I have about 6 text links, each in it's own table cell on the side of my page. When clicked these show or hide some layers i have on the right which pop up information about that topic.

    I want to have the colour behind the link to change when that link is clicked to indicate that it is active. When another link is clicked, the hilighted link needs to go back to a white background and the new link needs to have a coloured background.

    I hope that all makes sense, any help greatly appreciated.

    -Candrias
    eTheory - the theory of revolution

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    something like this
    Code:
    var navIDs = new Array('nav1','nav2','nav3','nav4');
    var hiliteColor = '#CCC';
    var defColor = '#FFF';
    
    function updateNav(cell) {
    	for (var i in navIDs)
    		cell.style.background-color = (navIDs[i] != cell.id) ? defColor : hiliteColor ;			
    	}
    	
    <table>
    <tr>
    	<td id="nav1" onClick="updateNav(this)">Nav Item 1</td>
    </tr>
    <tr>
    	<td id="nav2" onClick="updateNav(this)">Nav Item 2</td>
    </tr>
    <tr>
    	<td id="nav3" onClick="updateNav(this)">Nav Item 3</td>
    </tr>
    <tr>
    	<td id="nav4" onClick="updateNav(this)">Nav Item 4</td>
    </tr>
    </table>


  •  

    Posting Permissions

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