Jump to content

Rollover effect applied to straight up text?


MandarinAlone

Recommended Posts

Salutations, Im trying to figure out how to specify regular text as the target of a rollover effect using the mouseOver/Off events. I just wanted a simple highlighting effect on some text I used CSS to position. I know I could have gone with just gifs as buttons with no backgrounds, but I wanted to do this with as few images as possible for a reason.Specifically, after the Function script statement, what is the DOM name I use to specify text, if thats even possible? Maybe Im a moron and its right in front of my face, but right about now after a few hours I just cant seem to make sense of my O'Reilly DHTML reference book... :)

Link to comment
Share on other sites

I'm not quite sure if i understand what you want, maybe this? :)

<head><script>function change(val){ x=document.getElementById(val); x.style.color="white"; x.style.backgroundColor="black";}function changeBack(val){ x=document.getElementById(val); x.style.color="black"; x.style.backgroundColor="white";}</script></head><body><span id="text" onmouseover="change(this.id)" onmouseout="changeBack(this.id)">Mouse over me</span></body>

Link to comment
Share on other sites

  • 2 weeks later...
I'm not quite sure if i understand what you want, maybe this? :)
<head><script>function change(val){ x=document.getElementById(val); x.style.color="white"; x.style.backgroundColor="black";}function changeBack(val){ x=document.getElementById(val); x.style.color="black"; x.style.backgroundColor="white";}</script></head><body><span id="text" onmouseover="change(this.id)" onmouseout="changeBack(this.id)">Mouse over me</span></body>

Man why does it always seem to vary in ways that just throw me? Is there no one way to create a rollover using JavaScript? The syntax looks different than what I was fumbling with and found on other tutorial sites. "(val)" would be value, correct? But what value? This is my second time through the DHTML class and for some reason (well actually, several well-known reasons...) I cant seem to get this stuff... "x" would be what again? Crap, no career in web design for me... :)
Link to comment
Share on other sites

Hey don't worry about it, it will come to you soon enough. It takes practise and more practise.There are many ways to do 1 job with javascript, it depends on the coders style, i like doing things one way, the next guy might do it another.val is shorthand for valuewhat is the value, it's the value of the span id, notice how i pass this.id to the function, so the value being passed is textfunction change(val){}<span id="text" onmouseover="change(this.id)" >what is x?x=document.getElementById(val);we know that the value of val is text, so x = the element on the page with the id text, which is the span tag.Does that make sense?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...