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
    New to the CF scene
    Join Date
    May 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    functions don't work, need help changing things

    Hi everyone. I've written a small function to change the background color of an anchor. It changes when somebody clicks on it from a list of FAQs.

    I added a line to try to change back to white when somebody clicks on another one so that only the one most recently clicked on is highlighted.

    Also, anytime I try to put something in a function, it stops working. Any ideas?

    Code:
    var aneo;
    function setbg(aneo)
    {
    document.getElementByTagName("A").style.backgroundColor='white';
    document.getElementById("aneo").style.backgroundColor='yellow';
    return 0;
    }
    Code:
     <a href="#cash" onClick="javascript:setbg('cash');">...</a>
    Any suggestions? Thanks!

  • #2
    New Coder
    Join Date
    Jun 2002
    Location
    Sydney, NSW, Australia
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts
    getElementsByTagName() returns an array of all the tags on your page. So you would need to do something like this instead;

    Code:
    var links = document.getElementsByTagName("A");
    for (i=0; i<links.length; i++) {
    	links[i].style.backgroundColor = "white";
    }


  •  

    Posting Permissions

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