Newbie question

Discussion in 'JavaScript' started by Darkhodge, Jan 1, 2007.

  1. #1
    Hey,


    First of all sorry - this is probably a dumb question but I'm a complete newbie when it comes to javascript! :eek:

    I have a site where I'll have multiple links on a page. I want the anchor text to change when they are clicked. For example:

    
    Link 1 Anchor Text
    Link 2 Anchor Text
    Link 3 Anchor Text
    
    Code (markup):
    I want the text to change to:

    
    Done
    Link 2 Anchor Text
    Done
    
    Code (markup):
    Once links 1 and 3 have been clicked. Also is it possible to change the color of the links to black once they've been clicked?


    Thanks!

    Hodge :)
     
    Darkhodge, Jan 1, 2007 IP
  2. OWL_on_NG

    OWL_on_NG Active Member

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    86
    #2
    OnClick="this.text='Done';this.fgcolor='black'"
    Insert that in the <a> tag and it should work.
     
    OWL_on_NG, Jan 1, 2007 IP
  3. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #3
    Another method is with CSS. Example, insert this in the "head" of your html:

    
    <style type="text/css">
    a:visited { text-decoration: none; color: red; }
    </style>
    
    Code (markup):
     
    ajsa52, Jan 2, 2007 IP
  4. Darkhodge

    Darkhodge Well-Known Member

    Messages:
    2,111
    Likes Received:
    76
    Best Answers:
    1
    Trophy Points:
    185
    #4
    So do I put it into the tags like this? Btw in case I didn't say it before I want the links to open new windows when they get clicked.

    
    <a href = "http://www.google.com" target = "_blank" OnClick="this.text='Done';this.fgcolor='black'">Google</a>
    
    Code (markup):
    Thanks for your help but I had thought of that approach. The main thing at this stage is to get the anchor text to change to done permanently (for that page load) to "Done". :)


    Thanks,

    Hodge
     
    Darkhodge, Jan 2, 2007 IP
  5. Pat Gael

    Pat Gael Banned

    Messages:
    1,331
    Likes Received:
    68
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Pat Gael, Jan 2, 2007 IP
  6. Darkhodge

    Darkhodge Well-Known Member

    Messages:
    2,111
    Likes Received:
    76
    Best Answers:
    1
    Trophy Points:
    185
    #6
    Wait... I thought you can't change text dynamically like what I'm looking for with CSS. I know you can change the color of a link once it's been clicked with CSS but not change anchor text right? :confused:
     
    Darkhodge, Jan 2, 2007 IP