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 6 of 6
  1. #1
    New Coder
    Join Date
    Dec 2004
    Posts
    54
    Thanks
    0
    Thanked 0 Times in 0 Posts

    change link color when clicked

    Hi!

    I have menu in my page and an iframe that changes when the links in the menu are clicked. What I want to do is change the color of the link of the current page that is shown in the iframe. I guess it's just the same as change the color of the link once it is clicked. Is there any way for me to do this using Javacript?

    I would really appreciate any kind of help. Thanks!

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Check the source of the iframe and loop thru the parent document.anchors collection to match it with the one that has the same href value and change the class...

    .....Willy

  • #3
    Senior Coder
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    1,963
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Willy's suggestion is right on the money -- that would be the best way to go about it.
    The easiest way to go about it would be like so:
    Code:
    <a href="page2.htm" onclick="this.style.color = '#3aad22' ">Page 2</a>
    If you do decide to take the easy way out, don't do so unless you understand why Willy's suggestion is a better method.

    I take no responsibility for the above nonsense.


    Left Justified

  • #4
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    eh ... CSS anyone?

    PHP Code:
    a:link {colorblue;}
    a:active {colorred;}
    a:visited {colorpurple;} 
    the exact colours are up to you, of course.
    *keep it simple (TM)

  • #5
    New Coder
    Join Date
    Dec 2004
    Posts
    54
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your replies but what I need is something that when you click another link in the menu the current link goes back to its original color and the one clicked will change.

    The code snippet of mindlessLemming works great but if I could just find a way to modify it so that it would work like I mentioned above.

    Looking forward to all your help again. thanks!

  • #6
    Regular Coder ArcticFox's Avatar
    Join Date
    Jan 2004
    Location
    Vostok Station, AQ
    Posts
    602
    Thanks
    35
    Thanked 3 Times in 3 Posts

    Exclamation

    Quote Originally Posted by sassy_monix
    [...]something that when you click another link in the menu the current link goes back to its original color and the one clicked will change.


    a:link {color: blue;}
    a:active {color: red;}
    a:visited {color: blue;}





    <div> - putting your mind in a box since 1997


  •  

    Posting Permissions

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