| | |
Changing link text.
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Sep 2007
Posts: 1
Reputation:
Solved Threads: 0
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
The link
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?
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)
function exp(obj) { var el = document.getElementById(obj); el.innerHTML = 'This text has changed!'; }
The link
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<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?
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:
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)
<html> <script type="text/javascript"> function exp(obj) { if(obj.oldText){ obj.innerHTML = obj.oldText; obj.oldText = null; } else { obj.oldText = obj.innerHTML; obj.innerHTML = 'This text has changed!'; } } </script> <body> <a href="#" onclick="javascript:exp(this);">Click here 1!</a><br/> <a href="#" onclick="javascript:exp(this);">Click here 2!</a><br/> </body> </html>
![]() |
Similar Threads
- Link Popularity (Search Engine Optimization)
- Random image with text and link (JavaScript / DHTML / AJAX)
- Open In New Window Php (PHP)
- link text boxes with listbox (VB.NET)
- Getting rid off the border round link images (HTML and CSS)
- I have a link exchange on my site (Relevant Link Exchanges)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: "Must visit from" javascript wont work in IE...
- Next Thread: Showing Chat Msgs without reloading
| Thread Tools | Search this Thread |
acid2 ajax ajaxexample ajaxjspservlets array browser bug captchaformproblem cart checkbox child class close codes createrange() css cursor date debugger decimal dependent design disablefirebug dom dropdown editor element embed engine enter error events explorer ext file firefox focus form forms frameworks getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe images index internet java javascript javascripthelp2020 jquery jsf jsfile jsp jump libcurl listbox maps masterpage math media menu mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent paypal pdf php position post problem programming progressbar prototype redirect runtime safari scale scriptlets scroll search security shopping size software toggle unicode w3c web wysiwyg \n





