/    Sign up×
Community /Pin to ProfileBookmark

Change text with a link hover

Alright, I have set it up so that when someone hoves over a link an image in a div next to the links will change but I was wondering if I could change some text too? Can this be done and if so how?

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceJun 02.2006 — Show your link and code to change the image.
Copy linkTweet thisAlerts:
@CharlesJun 02.2006 — [code=html]<a href="http://ww.w3.org/" onmouseover="this.firstChild.data = 'Yes!'" onmouseout="this.firstChild.data = 'W3C'">W3C</a>[/code]
Copy linkTweet thisAlerts:
@BOB101authorJun 02.2006 — So Charles, is firstChild.data the name of the page with the text? So it would be like:
[code=html]<a href="http://ww.w3.org/" onmouseover="this.game1.html = 'Yes!'" onmouseout="this.game1.html = 'Game'">Game</a>[/code]
Copy linkTweet thisAlerts:
@CharlesJun 02.2006 — No.

"this" is the element itself, the A element with which we wish to monkey.

"firstChild" is the A element's first child, the text node.

"data" is the CDATA, character data, contained by the text node.

Use my example exactly as it is.
Copy linkTweet thisAlerts:
@BOB101authorJun 02.2006 — Charles,

It works but I want to change the text in another div not the link text itself. Is it possible to do that with mouseover?
Copy linkTweet thisAlerts:
@CharlesJun 02.2006 — The principal is the same and you have several options. Perhaps not the easiest but certainly the most portable is to give your div an ID - but make sure that the DIV contains something before you monkey with it, &nbsp; will do.

[code=html]<a href="game.html" onmouseover="document.getElementById ('div-ID').firstChild.data = 'Yes!'" onmouseout="document.getElementById ('div-ID').firstChild.data = 'Game'">Game</a>[/code]
Copy linkTweet thisAlerts:
@BOB101authorJun 02.2006 — Charles,

Is there a way that I can tell the link to show an HTML page inside the div on a mouseover using the same way?
Copy linkTweet thisAlerts:
@CharlesJun 02.2006 — Try[code=html]<iframe name="myFrame"></iframe>

<a href="http://www.w3.org" onmouseover="window.myFrame.location = this.href" target="myFrame">W3C</a>[/code]
Copy linkTweet thisAlerts:
@BOB101authorJun 02.2006 — Cool thanks, that what I'm looking for. But I want the link to show a different page, not it's url.
×

Success!

Help @BOB101 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...