Javascript: show/hide contents os <span>

SpaceshipSpaceship
SpaceshipSpaceship
SpaceshipSpaceship
Watch

Barrucadu

Established Member
Impact
64
I am attempting to show a <span> tag when the user hovers over a link, and hide it when they move the mouse off. But the code just dosn't work.

Here is my JavaScript:
Code:
function showSpan(name){
     document.getElementByName(name).style.display = "block";
}
function hideSpan(name){
     document.getElementByName(name).style.display = "none";
}

Here is my HTML:
Code:
<a href="Algorithms.html" onMouseOver="showSpan('Algorithms');" onMouseOut="hideSpan('Algorithms');">Algorithms</a>
<span name="Algorithms" style="display:none;"> - Test.</span>
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
1. in your span, replace name= with id=

2. in your function, replace both instances of getElementByName with getElementById

That should do it :)
 
1
Close
Yes.. and not so important but make onMouseOver and onMouseOut to lowercase if you want them to validate as XHTML.
 
1
Close
Ahhh, thats it. works perfectly, thanks.

PHP:
$cef->rep++;
$tm->rep++;

:)
 
0
Close
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Filters for activity feeds
Your news feed, Latest activity, and the activity tab on profiles now have filter buttons: All, Posts, Quick replies, and Other. Your...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back