Current location: Hot Scripts Forums » General Web Coding » JavaScript » [SOLVED] SwitchMenu - Active colour change


SwitchMenu - Active colour change

Closed Thread
  #1 (permalink)  
Old 04-29-10, 08:12 AM
rubee rubee is offline
New Member
 
Join Date: Apr 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
SwitchMenu - Active colour change

I used a switchmenu from Dynamic Drive and customised it as used for content instead of links.

The problem I'm having is that I want the active (open item) heading to change colour

I tried the onclick(this.style.color) thing. but that changed the colour permanently once clicked. And I would like it to revert back to normal once another menu is click.

Hope I'm making sense.

Much thanks.
  #2 (permalink)  
Old 04-29-10, 04:35 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
You will need to use a couple of global variables to store the current element and the current color of the current element.
Then use a function to restore the elements (previous element) color when you select a new element.
Here is an example using some buttons.
When you click on a button the onclick event listener passes a reference to the button object and the new color to a function (change_color()) which first restores the previous buttons color, then stores the current button object and it's current color and then changes it's color.
HTML Code:
<html>
<head>
<script>
var prev_element,prev_color;
function change_color(element,color)
{
 if(prev_element){prev_element.style.color = prev_color;}
 prev_element = element;
 prev_color = element.style.color;
 element.style.color = color;
 }
</script>
</head>
<body>
<button style="color:#000;" onclick="change_color(this,'#f00')">Button 1</button>
<button style="color:#000;" onclick="change_color(this,'#00f')">Button 2</button>
<button style="color:#000;" onclick="change_color(this,'#aa0')">Button 3</button>
<button style="color:#000;" onclick="change_color(this,'#0f0')">Button 4</button>
</body>
</html>
__________________
Jerry Broughton
  #3 (permalink)  
Old 05-01-10, 09:39 AM
rubee rubee is offline
New Member
 
Join Date: Apr 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Worked wonders! Thanks much!
Closed Thread

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to change the colour of the menu? srkssit HTML/XHTML/XML 13 02-11-09 12:25 AM
change background colour of another frame Bazzio JavaScript 10 08-15-05 07:17 PM
Please help change background colour Masuma The Lounge 1 05-02-05 11:33 AM
change colour of selected row in listview vbsoftwareengineer Visual Basic 0 02-19-05 09:35 AM
pls HELP VB 5.0 colour change K Z Visual Basic 1 12-10-04 02:19 AM


All times are GMT -5. The time now is 02:02 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.