SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Oct 2010
    Location
    Portland, Or
    Posts
    724
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    how do I make .show & .hide work.

    I set them to have both on click event. but while the .hide function worked. Once i added a .show it stopped working.
    HTML Code:
    <div id="text01">
    <p onclick="hide_para(this,1000);"> 
    Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. 
    </p>
    <input type="button" value="show" onclick="showPara('#text01',1000);">
    </div> <!--text1-->
    the jquery/js

    Code:
    function hide_para(element, speed){
    $(element).hide(speed);
    }
    
    function show_para(element, speed){
    $(element).show(speed);
    }
    how do I fix this please?
    thx
    D

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,873
    Mentioned
    208 Post(s)
    Tagged
    12 Thread(s)
    Hi there,

    Would it not be easier to use .toggle(), instead of defining separate actions to hide and display the content?

    Here's an example to get you started (using .slideToggle()):
    HTML Code:
    <!DOCTYPE html>
    <html>
      <head>
        <style>p { width:400px; }</style>
        <script src="http://code.jquery.com/jquery-latest.js"></script>
      </head>
      
      <body>
        <button>Toggle</button>
        <p>
          This is the paragraph to end all paragraphs.  You
          should feel <em>lucky</em> to have seen such a paragraph in
          your life.  Congratulations!
        </p>
        <script>
        $("button").click(function () {
          $("p").slideToggle("slow");
        });
        </script>
      </body>
    </html>

  3. #3
    SitePoint Guru
    Join Date
    Oct 2010
    Location
    Portland, Or
    Posts
    724
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hello Pullo!
    Will go head and try out your suggestion, thank you.


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
  •