SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: show/hide

  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    show/hide

    how can I show and hide images with jQuery. Currently I am using:

    HTML Code:
    <script>
    
    $("a.M").click(function () {
    $("p.M").fadeToggle();
    $("p.W").hide("slow");
    });
    $("a.W").click(function () {
    $("p.W").fadeToggle();
    $("p.M").hide("slow");
    });
    </script>
    That shows and hides but when I click the button (a href) twice the image changes to the correct one on the first click, but on the second click it disappears. Any ideas on how not to have it completely disappear on the second click? Thanks

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,127
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    It would do that, because you are using fadeToggle(). On the first click, it wasn't visible, so it goes from not visible to visible. On the second click, it is visible, so it is going from visible to not visible.

    If you want it to always be present (no matter how often they click the link), you want to use .show() or .fadeIn() instead of .fadeToggle()

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank @cpradio, worked great!

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you @cpradio, worked great!


Tags for this Thread

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
  •