Forum Moderators: open

Message Too Old, No Replies

How to switch between two different 'words'?

         

Nfra

4:18 pm on Jul 18, 2004 (gmt 0)



Hello out there.
I'm kind'a new to js and need some preliminary help.

I was wondering if it is possible to do the following using js.:
I want to place a link on a webpage that triggers a switch.
I.e. the word 'hello' is written into the page when it is first loaded. Then when you press a link the word 'hello' switches to 'goodbye'

I need this feature to work without the intire page being reloaded.

It's probably easy - well if you know the answer, that is.
Any help would be highly apreciatet.

cheers

Bernard Marx

4:51 pm on Jul 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



'Tis very easy, that one...

1. Put your word into an element of it's own. A span is good, as it doesn't have to have any stylistic effect.

2. Give the span an id: <span id="swap">hello</span>

3. Your link (doesn't need to be a link BTW. Use onclick on any element):


<a href="#" onclick="document.getElementById('swap').innerHTML='goodbye'">