• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

using image in anchor link - want to change it once link is visited

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I have the following question on what I am trying to do in javascript.

On a page I am using an image as part of a link...

<A HREF="testpage.html"><img src="images/not_visited_yet.jpg" border="0" ></A><br>

similar to how you can change a link to a different color once a user has visited that link, I would like to change images so that once the link has been visited the first time, it uses this...

<A HREF="testpage.html"><img src="images/already_visited.jpg" border="0" ></A><br>

I am relatively new to javascript so I am not sure if this is very simple or hard to do. I know using just html it's pretty trivial to display links that have already been visited in a different color. In this case however I want to display a different image.
I did check the tutorial I am using but I couldn't find any thing that explicitly showed how to do this.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might get the CSS :visited selector to do what you want.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To add a little more details. Instead of using an img tag, use a div element and make the image a background. This is easily swapped out using CSS as Paul explained. No script necessary!

Also, don't use uppercase for HTML; use all lowercase. While uppercase may work, it looks weird and amateurish.
 
reply
    Bookmark Topic Watch Topic
  • New Topic