Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

changing link background image dynamically

 
david arnold
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a few links on a web page, each of link has a background image, i want to change the background image when the link is clicked , related code as below:


First, I tried to use javascript to change the link class(method 2), then I tried to change the link background image directly(method 1), I also tried to define the link active through css, all of them does not perform the task I need. Please help to figure out the problem.

Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
david arnold wrote:
document.getElementById(linkID).className = "title_link_error_no_select";

There is no such class in your (shown) CSS.
 
david arnold
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh, i forgot to to include that in the post, it is similar to the others except it has different background image.



Thank you.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, what's the next debugging step? For example, have you 100% verified that the expression document.getElementById(linkID) references the expected element?

And, you do realize that assigning to className replaces all other classes, right?

 
david arnold
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Bear.

Yeah, document.getElementById(linkID) point to the right element, and I just tried


Which works, without the resetting the attribute innerHTML, both does not work. I do not know why.

I am not very sure if setting the className to that element will replace the old one, now I am sure after your informing .

Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic