Current location: Hot Scripts Forums » General Web Coding » JavaScript » How can I change and then restore a links content using onClick.


How can I change and then restore a links content using onClick.

Reply
  #1 (permalink)  
Old 09-22-05, 07:01 AM
Joe_Bloggs Joe_Bloggs is offline
Newbie Coder
 
Join Date: Sep 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation How can I change and then restore a links content using onClick.

Hi,
I am trying to display a link, which when clicked will eventually start an image slideshow, the link contents will change to 'Pause' and when the changed link is clicked again, the original link content 'View slideshow' is restored.
Using the code below, I am able to perform the first content change, but I am struggling to work out how to restore the link back to its original content.
If someone can offer some advice on this then I would be very grateful.

<html>
<head>
<script type="text/JavaScript">
function setLinkContent(link, content)
{
if (document.all)
{
link.innerText = content;
}
else if (document.getElementById)
{
link.firstChild.nodeValue = content;
}
}
</script>
</head>
<body>
<a href="#" onClick="setLinkContent(this, 'Pause');">View Slideshow</a>
</body>
</html>
Reply With Quote
  #2 (permalink)  
Old 09-22-05, 07:22 AM
ben.periton ben.periton is offline
Wannabe Coder
 
Join Date: Oct 2004
Posts: 183
Thanks: 0
Thanked 0 Times in 0 Posts
How about

<html>
<head>
<script type="text/JavaScript">
function setLinkContent(link, content, previous) {
if (document.all) {
if (link.innerText == content) {
link.innerText = previous;
} else {
link.innerText = content;
}
}
else if (document.getElementById) {
if (link.firstChild.nodeValue == content) {
link.firstChild.nodeValue = previous;
} else {
link.firstChild.nodeValue = content;
}
}
}
</script>
</head>
<body>
<a href="#" onClick="setLinkContent(this, 'Pause', 'View Slideshow');">View Slideshow</a>
</body>
</html>
__________________
Ben Periton
http://ben.periton.co.uk
Reply With Quote
  #3 (permalink)  
Old 09-22-05, 08:18 AM
Joe_Bloggs Joe_Bloggs is offline
Newbie Coder
 
Join Date: Sep 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Many thanks Ben, that works great.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i add a record AND send an email in one step? nickleidecker ASP 2 10-14-03 07:12 PM
change my field in this example sal21 ASP 3 07-14-03 02:49 AM


All times are GMT -5. The time now is 10:54 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.