views:

402

answers:

3

Hi all, I need some help to set a link as active as default when the page load the first time.

<style type="text/css">
a{
color:black;
}
a:hover{
color:white;
}
a:active{
color:blue;
}
</style>


<div>
<!--I want this fisrt link to be set as active by default-->
<a href="#"/>
<!--I want this one as normal-->
<a href="#"/>
</div>

I did add more information to clarify the question.

Any help would be very much apreciated.

Thanks.

+2  A: 

If you can change your markup to this:

<div>
<!--I want this fisrt link to be set as active by default-->
<a href="#" id="focusmeplease"/>
<!--I want this one as normal-->
<a href="#"/>
</div>

Then you can use this JavaScript:

document.getElementById('focusmeplease').focus();

Attach that JavaScript to page load however you like (I like this way, unless you're using jQuery, in which case use $(document).ready()).

Dominic Rodger
Thanks, it worked like a dream.
Cesar Lopez
A: 
  1. Mark the "a" tags with a class (like "focus").
  2. Set all the active "a" tags in the class "focus" with your preferred look.

<style type="text/css">
a
{color:black;}
a:hover
{color:white;}
a.focus:link, a.focus:visited
{color:blue;}
</style>

<div>
<a href="#" class="focus">This link is active by default.</a>
<a href="#">This is a normal link.</a>
</div>

Final note: I have also corrected the "a" tag because was wrong.

Davmuz
for some reason, does not work :-(, thanks anyway
Cesar Lopez
This will not work. The first link will become blue only when it is being click. No default appearance. Down vote.
Martin
Sorry, I do not understand well.I have correct it, please verify if now it have the behavior that you want.
Davmuz
You can add or remove the following proprieties in order to change the behavior: link, visited and hover.
Davmuz
A: 
a{
  color:black;
}
a:hover {
  color:white;
}
a:active, div a:first-child {
  color:blue;
}

Supported by most recent browsers, but not much more than that.

Tor Valamo
Sorry I cant get it to work, does it works on IE7 too?Thanks
Cesar Lopez
no, I said most recent browsers.
Tor Valamo