Solved

change the background color of a link using css

Posted on 2011-03-13
8
182 Views
Last Modified: 2012-05-11
Hi, I have a page with an iframe and links. When I click on the link the background of that link change, but when I click anywhere in the document the background changes back.
How can I keep the :active background until another link is clicked no matter what happens in the iframe or elsewhere in the document?

my links look like this:
<span><a class="index_vertical_links" href="javascript:jumpto('<?php echo "$main_output"; ?>')" >Page</a></span>
<span><a class="index_vertical_links" href="javascript:jumpto('<?php echo "$display_form"; ?>')" >some other page</a></span>
<span><a class="index_vertical_links" href="javascript:jumpto('<?php echo "$add_new?cat_add=1"; ?>')" >other page</a></span>

my css looks like this:
a.index_vertical_links:link,a.index_vertical_links:Visited
{
width:235px;
height:20px;
padding-left:20px;
float:left;
color:#ffffff;
background-color:#3f5d83;
border-right:1px solid #264266;
border-top:1px solid #3f5d83;
border-bottom:1px solid #3f5d83;
text-align:left;
text-decoration:none;
letter-spacing:1pt;
word-spacing:0pt;
font-weight:normal;
font-size:12px;
font-family:MS Sans Serif,Arial,sans-serif;
line-height:18px;
}

a.index_vertical_links:Hover
{
width:234px;
height:20px;
border-left:1px solid #264266;
float:left;
color:#e4ab13;
background-color:#787b6a;
border-right:1px solid #787b6a;
border-top:1px solid #264266;
border-bottom:1px solid #264266;
text-align:left;
text-decoration:none;
letter-spacing:1pt;
word-spacing:0pt;
font-weight:normal;
font-size:12px;
font-family:MS Sans Serif,Arial,sans-serif;
line-height:18px;
}

a.index_vertical_links:active,a.index_vertical_links:focus
{
width:235px;
height:20px;
padding-left:20px;
float:left;
color:#e4ab13;
background-color:#787b6a;
border-right:1px solid #787b6a;
border-top:1px solid #264266;
border-bottom:1px solid #264266;
text-align:left;
text-decoration:none;
letter-spacing:1pt;
word-spacing:0pt;
font-weight:normal;
font-size:12px;
font-family:MS Sans Serif,Arial,sans-serif;
line-height:18px;
}
0
Comment
Question by:ikon32
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 35124783
try this simple thing

a.index_vertical_links_visited
{
width:235px;
height:20px;
padding-left:20px;
float:left;
color:#ffffff;
background-color:#3f5d83;
border-right:1px solid #264266;
border-top:1px solid #3f5d83;
border-bottom:1px solid #3f5d83;
text-align:left;
text-decoration:none;
letter-spacing:1pt;
word-spacing:0pt;
font-weight:normal;
font-size:12px;
font-family:MS Sans Serif,Arial,sans-serif;
line-height:18px;
}

<span><a class="index_vertical_links" href="javascript:this.setAttribute('class','index_vertical_links_visited');jumpto('<?php echo "$main_output"; ?>')" >Page</a></span>
0
 

Author Comment

by:ikon32
ID: 35124872
thanks for the comment!  I tried and when I clicked on the link it rerurn this error:
Webpage error details

Message: Object doesn't support this property or method
Line: 1
Char: 1
Code: 0
URI:  index.php

0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 35124934
remove the echo part and try once

<span><a class="index_vertical_links" href="javascript:this.setAttribute('class','index_vertical_links_visited');">Page</a></span>



0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ikon32
ID: 35124955
same error
0
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 35124972
ok, then try this solution

http://stackoverflow.com/questions/2490627/how-can-i-reliably-set-the-class-attr-w-javascript-on-ie-ff-chrome-etc

<span><a class="index_vertical_links" href="javascript:this.className = 'index_vertical_links_visited';">Page</a></span>
0
 

Author Comment

by:ikon32
ID: 35125034
tried this without error but again when i click anywhere the background is changing back.
<span><a class="index_vertical_links" href="javascript:this.className = 'index_vertical_links_visited';jumpto('<?php echo "$display_form"; ?>')">Page</a></span>

Going over to check that question, if you can think of anything else please post!  
0
 

Author Comment

by:ikon32
ID: 35125184
cant get it right... can it be done with just css?
0
 

Author Closing Comment

by:ikon32
ID: 35224228
thank you
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Open dialog with server side controls in it 3 46
ASP sending two datas 2 23
Html date format 9 20
disable open new tab with right mouse click in <a> tag 3 19
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question