Passing text from variable in a link

D

da

I have a link which display a text when moving the mouse cursor over
the link, using CSS, like this:

CSS :
a { z-index: 20 }
a .alt { display: none }
a:hover { color: #FF3300; display: inline; }
a:hover .alt {
display: inline; position: absolute; z-index: 30;
margin: 1em 0 0 -2em; width: 10em; padding: 0.2em 0.3em;
color: #FFCC00; border-style: outset; text-decoration:none;
background-color: #006699;
}

HTML:
<a href="#">link<span class="alt">Mouse on link</span></a>

I like to put the text in a variable:
var textdisplay = "Mouse on link"

how do I refer to this variable in the link ?

DS
 
P

Peter Michaux

I have a link which display a text when moving the mouse cursor over
the link, using CSS, like this:

CSS :
a { z-index: 20 }
a .alt { display: none }
a:hover { color: #FF3300; display: inline; }
a:hover .alt {
display: inline; position: absolute; z-index: 30;
margin: 1em 0 0 -2em; width: 10em; padding: 0.2em 0.3em;
color: #FFCC00; border-style: outset; text-decoration:none;
background-color: #006699;

}

HTML:
<a href="#">link<span class="alt">Mouse on link</span></a>

I like to put the text in a variable:
var textdisplay = "Mouse on link"

how do I refer to this variable in the link ?

DS

You can change the contents of the span something like this untested
code...

<a href="#">link<span class="alt" id="mySpan">Mouse on link</span></a>

<script type="text/javascript">
var textdisplay = "Mouse on Link";
document.getElementById('MySpan').innerHTML = textdisplay;
</script>

Peter
 
A

ASM

En réponse à da qui nous a susurré, en date du : 29/07/07 21:30, le
message sibyllin suivant :
I have a link which display a text when moving the mouse cursor over
the link, using CSS, like this:

CSS :
a { z-index: 20 }
a .alt { display: none }
a:hover { color: #FF3300; display: inline; }
a:hover .alt {
display: inline; position: absolute; z-index: 30;
margin: 1em 0 0 -2em; width: 10em; padding: 0.2em 0.3em;
color: #FFCC00; border-style: outset; text-decoration:none;
background-color: #006699;
}

HTML:
<a href="#">link<span class="alt">Mouse on link</span></a>

I like to put the text in a variable:
var textdisplay = "Mouse on link"

how do I refer to this variable in the link ?

???
You want to get the span's content ?
or do you want to give to it the value of your variable ?
With only a specific link ? or all of them ?
On which moment ?

window.onload = function() {
var textdisplay = "Mouse on link";
var A = document.links;
// or :
// if(document.getElementsByTagName('A')
// var A = document.getElementsByTagName('A');
if(!!A && A.length>0)
for(var i=0; i<A.length; i++)
if(A.href &&
A.getElementsByTagName &&
A.getElementsByTagName('SPAN') &&
A.getElementsByTagName('SPAN').length>0)
A.getElementsByTagName('SPAN')[0].innerHTML = textdisplay;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top