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 4 of 4
  1. #1
    New Coder
    Join Date
    May 2009
    Location
    Bangalore
    Posts
    75
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Question Changing a link's color after clicking on it and staying on that page.

    HI All,

    Can anyone tell how to Change a link's color after clicking on it and staying on that page.Please help me its urgent.

    Thanks in Advance ..

  • #2
    New Coder
    Join Date
    Aug 2003
    Location
    Derby, UK
    Posts
    97
    Thanks
    0
    Thanked 14 Times in 14 Posts
    This is not a PHP question, however: this would be done easiest I think by assigning an id to the link then using js to change the color e.g.

    PHP Code:
    <a href="#" id="mylink" onclick="document.getElementById('mylink').style.color='red';return false;">Click me</a
    see http://www.metatest.co.uk/testclick.htm for live example.

    HTH,

    Dai

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    javascript is not reliable for this purpose. Take a look at a CSS based method at http://www.codingforums.com/showpost...64&postcount=3
    Last edited by abduraooft; 02-17-2010 at 12:40 PM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #4
    New Coder
    Join Date
    Aug 2003
    Location
    Derby, UK
    Posts
    97
    Thanks
    0
    Thanked 14 Times in 14 Posts
    One of us is missing the point: the OP said

    after clicking on it and staying on that page
    so having a cascade dependent style e.g. using page ids does not help.

    Furthermore the :visited style will presumably not be applied until the page reloads hence the question (not tested the latter I must confess)

    :hover and :active work when it is hovered and clicked but I don't think are persistent, so I cannot see any way to do this that does not involve javasccript, unless you reframe the question so that page reload is allowed, in which case it is trivial.

    Regards,

    Dai

    P.S.

    After some testing :active does actually remain on a link after clicking, but only until another link is clicked (or possibly it loses focus etc.) so may or may not be any use to OP :visited is a long term think and probably won't suit their purposes.

    http://www.metatest.co.uk/testclick.htm
    Last edited by DaiWelsh; 02-17-2010 at 12:59 PM. Reason: Further testing


  •  

    Posting Permissions

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