Jump to content

Text and bg color for current page


Recommended Posts

I try to change font colour and background colour for current link as:

window.onload = function() {    var navbars = new Array("topNav", "sideNav"); // navbars    for (j = 0; j < navbars.length; j++) {        anchors = document.getElementById(navbars[j]).getElementsByTagName("a");        var url = window.location.href.split("?")[0];        for (i = 0; i < anchors.length; i++) {            if (anchors[i].href == url) {                anchors[i].style.color = "red";                anchors[i].style.background-color = "white";            }        }    }}

Text works, but not bg color... Why does this not work?Son

Link to post
Share on other sites

Just a little clarification on dsonesuk's fix, JavaScript messed up when it was created and they didn't acknowledge the guys working on CSS. So, we have the same style properties but they have different names.I always keep this as a reference. http://codepunk.hardwar.org.uk/css2js.htm

Link to post
Share on other sites
should work, try thisfunction dothis(){anchors = document.getElementsByTagName("a");for(i=0;i<anchors.length;i++){anchors.style.backgroundImage='url(right.png)';}}window.onload=dothis;
Still does not work... Could it be a cross-browser issue? I work with Firefox...SonSon
Link to post
Share on other sites

i tested this in firefox! heres the whole script<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title><script type="text/javascript">/*<![CDATA[*//*---->*/function dothis(){anchors = document.getElementsByTagName("a");for(i=0;i<anchors.length;i++){anchors.style.backgroundImage='url(right.png)';}}window.onload=dothis;/*--*//*]]>*/</script> <style type="text/css"></style></head><body><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex.</p> <a href="#">aaaaaaaaaaaaa</a><a href="#">bbbbbbbbbbbbb</a><a href="#">ccccccccccccc</a><a href="#">dddddddddddddd</a><a href="#">eeeeeeeeeeeeeeeee</a><a href="#">fffffffffffffffffff</a></body></html>

Link to post
Share on other sites
. . . JavaScript messed up when it was created and they didn't acknowledge the guys working on CSS. So, we have the same style properties but they have different names.
More likely the other way around. If the CSS team even imagined JavaScript would ever have a CSS interface, they should have realized that a property like background-image simply cannot exist. The hyphen will be read as a subtraction operator, and there is no way around that. (Even overloading the operator wouldn't work, I think, since a hyphen really isn't an operator.) If any additional thinking needed to happen, it should have been the CSS team to do it.Most likely, the groups weren't even thinking about each other. In 1996, plain-vanilla JavaScript couldn't even get a reference to most page elements, because the id attribute didn't exist yet, so this kind of dynamic manipulation would not have been thought possible. Those were the days . . .
Link to post
Share on other sites

I agree you can’t blame JavaScript developers, JavaScript started to became available in 1995-96, while a type of css started to appear in 1993, which looks nothing like css we use at present, and is quiet frightening to look at, shudder... The styling was not fully defined as a standard, and many methods on how to implement styling where introduced until css1 W3C Recommendation came out in 1996. But four months before that a JavaScript-Based Styling was unleashed, which they could not have possibly have used current styling because it would have been totally impractical and so they used their own reference for styling.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...