www.webdeveloper.com
Results 1 to 7 of 7

Thread: Switching link text and href without page refresh..

Hybrid View

  1. #1
    Join Date
    May 2007
    Posts
    42

    Switching link text and href without page refresh..

    I have a "pause" link that I want to read "play" after the javascript behavior has been paused. However, I want to do so without a page refresh. Restated, I want a play/pause toggle. Here is a example slideshow page of where I would like to use that type of functionality.

    Any ideas?

    Thank you all in advance!

    bt
    Last edited by cgm225; 01-12-2008 at 04:29 PM.

  2. #2
    Join Date
    Oct 2006
    Location
    Ontario Canada
    Posts
    1,160
    Here is a sample that you can work into your current code to do this.
    Code:
    function showControl()
    {
    	var control = document.getElementById("control")
    	var currentText = control.innerHTML;
    	
    	if (currentText == "Play")
    	{
    		control.innerHTML = "Pause";
    	}
    	else
    	{
    		control.innerHTML = "Play";
    	}
    }
    
    </script>
    <a href="#" id="control" onclick="showControl();">Play</a>
    Drew

  3. #3
    Join Date
    May 2007
    Posts
    42
    What function (similar to innerHTML) can be used to specify the href of an element?

  4. #4
    Join Date
    Jan 2008
    Posts
    45
    .getAttribute('href');
    .setAttribute('href','your new link');

    the link text you can access via .firstChild.nodeValue

  5. #5
    Join Date
    May 2007
    Posts
    42
    @Killzone_Kid - thank you so much for your reply.

    However, could you explain the .firstChild.nodeValue comment a little more because I don't completely follow what that is/does.

    Thanks again!

  6. #6
    Join Date
    Jan 2008
    Posts
    45
    What's between <a> and </a> is your text of the link which is also child to the <a> element. So .firstChild specifies you need to look for the first node right after <a> which is the text node with the text of the link and .nodeValue should get you the value. Well something like that.

  7. #7
    Join Date
    Nov 2012
    Posts
    4
    widely used script to hide and show

    <script language="javascript">
    var $=function(id){return document.getElementById(id);}
    function toggleDisplay(id){
    if($(id).style.display=="block"){
    $(id).style.display="none";
    }else{
    $(id).style.display="block";
    }

    }
    </script>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles