Hi there Δημήτρης,

The two .toggle() methods are very different (and, therefore, often confusing to new users of jQuery):

The first one toggles the show and hide effects: for example,
   .toggle('slow')
The second one is a compound event handler that triggers 2 alternating functions: for example,
  .toggle(function() {
    // Stuff to do every *odd* time the element is clicked;
  }, function() {
    // Stuff to do every *even* time the element is clicked;
  });

It looks like you're trying to trigger an even handler inside an event handler?

Please try this instead:

$(function(){
   $('.desc span:first-child').toggle(function() {
     $(this).next().hide();
   }, function() {
     $(this).next().show();
   });
});

If all you are doing is hiding and showing the next sibling element, though, you could do the same thing this way:

$(function(){
  $('.desc span:first-child').bind('click', function() {
    $(this).next().toggle();
  });
});

Hope that helps.

--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com



On Feb 11, 2007, at 8:02 AM, Δημήτρης Χρυσομάλλης wrote:

Hello,
I am new to jquery and I am having a problem with toggle( fn, fn). The code below does not seem to work (no errors though). But if I call toggle() with no arguments, it works fine. The thing is, I need to do different things on each click. Might this be a bug?

<script type="text/javascript">
$(function(){
 $('.desc span:first-child')
 .bind("click", function(){
 $(this)
 .next()
 .toggle( function(){ $(this).hide(); },
             function(){ $(this).show(); } );
 });
});
</script>

I am using it with this markup:

<div class="row">
 <div class="cell  desc" id="s_desc">
  <span id="s_desc_caption">description:</span>
  <span id="s_desc_content">lorem ipsum...</span>
 </div>
</div>

Thank you.
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to