Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-26-2008, 04:17 AM   PM User | #1
taylortsantles
New Coder

 
Join Date: Jul 2008
Posts: 50
Thanks: 8
Thanked 0 Times in 0 Posts
taylortsantles is an unknown quantity at this point
Hide a css styled link on hover with JavaScript

Okay, us CSS nerds could not figure this out in css and we need JavaScript help.

Here is a link to the menu I'm working with:

http://www.ironforgeministries.com/Eyetech/index.html

I already have it set so that when I apply an <a class="on"></a> it will apply the style in my style sheet. What I want to know is this: How do I make it so that when I roll over the other links that, the styling for the one active disappears. Meaning, if it were on a page called "home", it would have a grey arrow next it and it would stand out different from the other links, but when you roll over the other links, I want that arrow and the styling on the "home" to disappear. I know the only way to do it is in JavaScript. Can anyone provide me with the code I would need to do it? Here is my css for the menu:


Code:
Code:
ul#sublink {
	font: 1em Arial, Helvetica, sans-serif;
	color: #666;
	padding-bottom: 4px;
	line-height: 20px;
	list-style: none;
	list-style-type: none;
}

ul#sublink li a {
	text-decoration: none;
	color: #666;
	display: block;
	padding-left: 40px;
	line-height: 25px;
}
	ul#sublink li a.on {
		background: transparent url(Images/arrow_grey.png) no-repeat 0px 4px;
	}
	ul#sublink li a:hover, ul#nav li.selected a.on {
		background: transparent url(Images/arrow.png) no-repeat 0px 4px;
		color: #0a87ac;
	}
taylortsantles is offline   Reply With Quote
Old 09-26-2008, 04:32 AM   PM User | #2
rangana
Senior Coder

 
rangana's Avatar
 
Join Date: Feb 2008
Location: Cebu City, Philippines
Posts: 1,752
Thanks: 65
Thanked 372 Times in 365 Posts
rangana will become famous soon enoughrangana will become famous soon enough
This is a shot in the dark, try to have this script:
Code:
<script type="text/javascript">
window.onload=function(){
for(var i=0,a=document.getElementById('sublink').getElementsByTagName('a');i<a.length;i++)
	{
	a[i].onmouseover=function()
		{
		removeClass();
		a[i].className='on'; // Set the class Name to on
		}
	}
}
function removeClass()
{
for(var i=0,a=document.getElementById('sublink').getElementsByTagName('a');i<a.length;i++)
	a[i].className=''; // Reset class names
}
</script>
It was basing on your CSS, if nothing works, please show us the markup.
__________________
Learn how to javascript at 02geek

The more you learn, the more you'll realize there's much more to learn
Ray.ph
rangana is offline   Reply With Quote
Old 09-26-2008, 04:41 AM   PM User | #3
taylortsantles
New Coder

 
Join Date: Jul 2008
Posts: 50
Thanks: 8
Thanked 0 Times in 0 Posts
taylortsantles is an unknown quantity at this point
Rangana, your code worked great. Is there any way to have the "on" class re-appear when the mouse moves away from the menu?

Thank you so much!

Last edited by taylortsantles; 09-26-2008 at 04:44 AM..
taylortsantles is offline   Reply With Quote
Old 09-26-2008, 05:24 AM   PM User | #4
rangana
Senior Coder

 
rangana's Avatar
 
Join Date: Feb 2008
Location: Cebu City, Philippines
Posts: 1,752
Thanks: 65
Thanked 372 Times in 365 Posts
rangana will become famous soon enoughrangana will become famous soon enough
Have a try on adding highlighted:
Code:
a[i].onmouseover=function()
		{
		removeClass();
		a[i].className='on'; // Set the class Name to on
		}
	a[i].onmouseout=function()
		{
		removeClass();
		a[i].className='on'; // Set the class Name to on
		}
I'm uncertain how this would work, not unless I could be able to see the markup.

Hope that helps.
__________________
Learn how to javascript at 02geek

The more you learn, the more you'll realize there's much more to learn
Ray.ph
rangana is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:03 PM.


Advertisement
Log in to turn off these ads.