Changing link text.

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Sep 2007
Posts: 1
Reputation: Ventrix is an unknown quantity at this point 
Solved Threads: 0
Ventrix Ventrix is offline Offline
Newbie Poster

Changing link text.

 
0
  #1
Sep 16th, 2007
Hello,

I have a link that carrys out a DHTML function within my page, and once this link is clicked, i use the following js to change the text of the link.

In an external js file
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function exp(obj) {
  2. var el = document.getElementById(obj);
  3. el.innerHTML = 'This text has changed!';
  4. }

The link
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <a name="a" href="javascript:exp('a');">Click here!</a>

So, once clicked, the text changes from Click here!, to This text has changed!. But i want to be able to revert to the original text, once the link is clicked again.

An example is http://demo.rockettheme.com/apr07/ The top panel 'Open Control Panel' changes and then reverts the link text on subsequent clicks.

Any help please?
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 182
Reputation: alpha_foobar is an unknown quantity at this point 
Solved Threads: 3
alpha_foobar's Avatar
alpha_foobar alpha_foobar is offline Offline
Junior Poster

Re: Changing link text.

 
0
  #2
Sep 17th, 2007
Hi,
If you want to do this with a lot of different links and for it to work well in IE and Firefox, then you might want to change it a little... alternatively, I would use an ID attribute instead of a name... Anyhow, take a look at this:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2. <script type="text/javascript">
  3. function exp(obj) {
  4. if(obj.oldText){
  5. obj.innerHTML = obj.oldText;
  6. obj.oldText = null;
  7. } else {
  8. obj.oldText = obj.innerHTML;
  9. obj.innerHTML = 'This text has changed!';
  10. }
  11. }
  12. </script>
  13. <body>
  14. <a href="#" onclick="javascript:exp(this);">Click here 1!</a><br/>
  15. <a href="#" onclick="javascript:exp(this);">Click here 2!</a><br/>
  16. </body>
  17. </html>
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC