Solved

change the background color of a link using css

Posted on 2011-03-13
8
177 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
  • 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
 

Author Comment

by:ikon32
ID: 35124955
same error
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now