User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 456,485 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,786 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 2240 | Replies: 1
Reply
Join Date: Sep 2007
Posts: 1
Reputation: Ventrix is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Ventrix Ventrix is offline Offline
Newbie Poster

Changing link text.

  #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
function exp(obj) {
  var el = document.getElementById(obj);
  el.innerHTML = 'This text has changed!';
}

The link
<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?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2005
Location: Wellington, New Zealand
Posts: 182
Reputation: alpha_foobar is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 3
alpha_foobar's Avatar
alpha_foobar alpha_foobar is offline Offline
Junior Poster

Re: Changing link text.

  #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:

<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>
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 3:03 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC