Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple rollover

Status
Not open for further replies.

mettodog

Vendor
Jul 11, 2000
94
US
how do i do a simeple text rollover? so when my mouse hovers over text, it changes to different text.
 
Well you will have to enclose it in some kind of tag - which will become an object or node which you can reference using JavaScript. Here is how to do it for IE5 NS6:

...
</script>
function setText(object){
object.innerText = &quot;This is now different&quot;
}
</script>
...

...
<span onMouseOver=&quot;setText(this)&quot; origText=&quot;text here!&quot; onMouseOut=&quot;this.innerText=this.origText&quot;>text here!</span>...


You could extend this to work with many of these elements using one function, if you add that the function accepts a string as an argument, and then uses that string as the new innerText. This will also work with IE4.x.

Also I have created a variable belonging to the span object simply by defining it in the tag - this is far sinpler than using prototype - and gives a simple mouse out reset which can be cut and pasted into any tag - assuming variable naming is consistent.

Also you can use any tag which has innerText, <b>, <i> whatever. All you need is a node.

If you wanted to change the formatting of the text - then use InnerHTML instead of innerText - this way the new text could be a different color, size, weight etc...

hope this helps - ;-)
b[sup]2[/sup] - benbiddington@surf4nix.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top