/    Sign up×
Community /Pin to ProfileBookmark

Problem with CSS and javascript

Hi,

I’ve written a script to highlight the current page in the navigation by comparing the page location and link, and then using a background color and left border color to highlight the current page in the navigation.

My problem though, is that although the current page is highlighted by changing the background color, the border color doesn’t change for some reason. This tells me that the js is ok, but there must be a problem with the css.

Here’s the js code:

[code]
function selectVisited()
{
var nav = document.getElementById(‘navigation’);
var links = nav.getElementsByTagName(‘a’);

for (var i=0; i<links.length; i++)
{
if (links[i].href == location.href)
{
links[i].className = “current”; i<links.length;
}
}
}
[/code]

The function is called onLoad in the body tag.

Here’s the css:

[code]
[color=red].current[/color] {border-left: 3px solid #A0BAB6; background: #ECECEC; color: #968464; display: block}
[/code]

Note the default style for the links in the navigation bar is to have a 3px solid gray left border. On hover that left border changes to blue and the background color is set to pale gray. When it’s the selected page, that left border is supposed to be blue and a pale gray background color (just like when you hover over one of the links). My problem is that the background color changes, but the border color doesn’t.

Can anyone see a problem that I’m not seeing?

Thanks a bunch!

to post a comment
CSS

4 Comments(s)

Copy linkTweet thisAlerts:
@KDLAJun 12.2006 — Can you provide an example of the HTML you're using with this? Could be associated with the tag you're using.
Copy linkTweet thisAlerts:
@kelly23authorJun 12.2006 — Hi,

Sure, here's a sample of the html:
<i>
</i>&lt;table class="subnav" id="navigation"&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Shop by Category&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;a href="link1.html"&gt;Link 1 Text&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;a href="link2.html"&gt;Link 2 Text&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;a href="link3.html"&gt;Link 3 Text&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;


And here's some more of the css:
<i>
</i>table.subnav {margin-left: 5px; margin-right: 5px; padding-bottom:0; border: 1px solid #A0BAB6; border-collapse: collapse}
table.subnav td {padding:1px; padding-left: 5px; border: 1px solid #C9D6D1; border-left:0; border-right:0; color: #6F5A39}
table.subnav a {border-left: 3px solid #C5BCAD; margin-bottom: 1px; padding: 2px; color: E62858E; text-decoration: none; display: block; padding-left:5px}
table.subnav a:visited {margin-bottom: 1px; padding: 2px; color: #62858E; text-decoration: none; display: block; padding-left:5px}
table.subnav a:hover {border-left: 3px solid #A0BAB6; margin-bottom: 1px; padding: 2px; background: #ECECEC; color: #968464; display: block; padding-left:5px}
.current {border-left: 3px solid #A0BAB6; margin-bottom: 1px; padding: 2px; background: #ECECEC; color: #968464; display: block; padding-left:5px}
Copy linkTweet thisAlerts:
@ray326Jun 12.2006 — I think I'd do it in straight CSS by using an id on the body tag.
Copy linkTweet thisAlerts:
@kelly23authorJun 12.2006 — Hi,

I think I'd do it in straight CSS by using an id on the body tag.[/quote]
This is a dynamic e-commerce site and almost all pages use the same body tag, so I don't think that will work.

kelly
×

Success!

Help @kelly23 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...