943,771 Members | Top Members by Rank

Ad:
Sep 16th, 2007
0

Changing link text.

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Ventrix is offline Offline
1 posts
since Sep 2007
Sep 17th, 2007
0

Re: Changing link text.

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>
Reputation Points: 20
Solved Threads: 5
Junior Poster
alpha_foobar is offline Offline
182 posts
since May 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: "Must visit from" javascript wont work in IE...
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Showing Chat Msgs without reloading





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC