• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 243
  • Last Modified:

Show / Hide JQuery Script (Provided, working Example)

Hello All;

I found this script from:
www.designing4u.de (Show/Hide)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){  
  $('.ahref',this).toggle(
    function () {
      var id = $(this).attr('href');
      if($('.box'+id).text() == '') {  
       $(".box"+item.id).html(html).slideDown(1000); 
        $(this).html("hide");
      } else { 
        $(this).html('hide');  
        $('.box'+id).slideDown(1000);  
      }  
    },  
    function () {  
      var id = $(this).attr('href');
      $(this).html('show');  
      $('.box'+id).slideUp(1000);  
    }  
  );
});
</script>
</head>

<body>
<a href="1" class="ahref">show 1</a>
<a href="2" class="ahref">show 2</a>
<a href="3" class="ahref">show 3</a>
<div class="box1">1</div> 
<div class="box2">2</div> 
<div class="box3">3</div>
<div style="clear:left"></div>
</body>
</html>

Open in new window


OK, I LOVE this code, and it WORKS in my project, so I want to use it so badly, I can taste it.
Now, my question is the following.

When you run the code, the following happened.

Step #1: You have to click the
show 1
show 2
show 3

Step #2: Then you have to click the
show
show
show

Step #3: Then the layers will hide themselves.
So, this is an unneeded step, that I would prefer not to have.

Can someone please let me know what needs to be done in order to eliminate this extra step.

Thank you
Carrzkiss
0
Wayne Barron
Asked:
Wayne Barron
  • 2
  • 2
1 Solution
 
selvolCommented:
Try this my Friend....

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){  
  $('.ahref',this).toggle(
    function () {
      var id = $(this).attr('href');
      if($('.box'+id).text() == '') {  
       $(".box"+item.id).html(html).slideUp(1000); 
        $(this).html("hide");
      } else { 
        $(this).html('hide');  
        $('.box'+id).slideUp(1000);  
      }  
    },  
    function () {  
      var id = $(this).attr('href');
      $(this).html('show');  
      $('.box'+id).slideDown(1000);  
    }  
  );
});
</script>
</head>

<body>
<a href="1" class="ahref">show 1</a>
<a href="2" class="ahref">show 2</a>
<a href="3" class="ahref">show 3</a>
<div class="box1">1</div> 
<div class="box2">2</div> 
<div class="box3">3</div>
<div style="clear:left"></div>
</body>
</html>
                                  

Open in new window


I think I got the question.

Selvol
0
 
Wayne BarronAuthor Commented:
instead of just coping and pasting, I looked through the code.
Took my 2 glances, to catch on to the SlideUp and SlideDown, being changed around.

I wonder why the developer missed that one?

However, you rock "Selvol"
Carrzkiss
0
 
selvolCommented:
Don't be afraid to experiment with code.
That is just what I did.

I am glad to see you actually looked at the code and figured out what
was changed.


That in its self is really what I am here for (on EE).
I would rather answer questions knowing that the asker learns from it
and not just copies and pastes.......

Glad I could Help......

Selvol
0
 
Wayne BarronAuthor Commented:
You are not kidding there Selvol.

I helped this one person here a few years ago, and found out that all he did
Was copy and paste, and never paid one bit of attention to the code itself.
And then he started coming in and asking the same questions, over and over again.
It got sickening.
So I caught him on it, and made an example of him.
Then everyone that was helping him, started getting him to try different things
before they would assist him further.

I want to learn more, I want my knowledge to extend further than what it is.

Have a good weekend Selvol
Carrzkiss
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now