SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jan 2008
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Replacing button's with a single link.

    Code JavaScript:
    <script>
    window.onload = (function(){try{
     
    $("#showr").click(function () {
      $(".sharew:eq(0)").show("fast", function () {
    	// use callee so don't have to name the function
    	$(this).next().show("fast", arguments.callee);
      });
    });
    $("#hidr").click(function () {
      $(".sharew").hide(2000);
    });
     
    } catch(e){}});
    </script>

    Code HTML4Strict:
    <button id="showr">Show</button> <button id="hidr">Hide</button>

    I've been trying to replace 2 buttons with a single link. <a href="...

    Any idea how i can do this? I'm quite bad with JS.

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,609
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    In simple terms ...

    Code:
    <div id="divid">Content</div>
    <a href="#" onclick="toggle ('divid')">Show/Hide</a>
    Code JavaScript:
    <script type="text/javascript">
    function toggle (div) {
      var el = document.getElementById (div);
      if (el.style.visibility == 'hidden') {
        el.style.visibility = 'visible';
      } else {
        el.style.visibility = 'hidden';
      }
    }
    </script>
    Ian Anderson
    www.siteguru.co.uk

  3. #3
    SitePoint Member
    Join Date
    Jan 2008
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SiteGuru,

    I want to use the JS i already have to hide/show.

    But im trying to change the buttons to a single hide/show link. :-|

  4. #4
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,609
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Where does your code come from? Is it utilising a library?

    In short - your existing code creates 2 functions ... show() and hide(). If you want a single link then you basically need a toggle() function, like what I showed.
    Ian Anderson
    www.siteguru.co.uk

  5. #5
    SitePoint Zealot
    Join Date
    Dec 2007
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Guessing that's the prototype library.


Bookmarks

Posting Permissions

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