Hang on...now that I look at it, I think I understand #4. Is this
line:

var $this = $(this), size = $this.attr('href'), toggle = $('.' +
size);

the same as these lines:
var $this = $(this)
var size = $this.attr('href')
var toggle = $('.' + size);

?

On Sep 1, 9:41 am, Andy Matthews <[EMAIL PROTECTED]> wrote:
> Klaus...
>
> A few questions.
>
> 1) I'm assuming from your reply that there's no way to do this with
> plain ole hover/toggle then?
>
> 2) What is a closure?
>
> 3) Is there any performance hit when doing .each (then toggle) versus
> just doing .toggle?
>
> 4) Can you explain this line please?
>     var $this = $(this), size = $this.attr('href'), toggle = $('.' +
> size);
>
> On Sep 1, 4:43 am, Klaus Hartl <[EMAIL PROTECTED]> wrote:
>
>
>
> > Andy Matthews wrote:
> > > Is there a way to pass arguments from one anonymous function, (in
> > > either Toggle, or Hover) to the second? Ideally I'd like to be able to
> > > pass in whatever variables I choose, but I'd settle for being able to
> > > pass in $(this), the item that triggered the event.
>
> > > Here's the code:
>
> > > // I have a set of links which show/hide items on a chart
> > > $('a.display').toggle(function(){
> > >      var size = $(this).attr('href');
> > >      $('.' + size).hide();
> > > },function(size ){ // can I pass "size" through to this second
> > > function?
> > >      $('.' + size).show();
> > > });
>
> > > Anyone? If this is possible, then it needs to become part of the API
> > > docs because I can't find it anywhere on the site.
>
> > Closures are your friend:
>
> > $('a.display').each(function() {
> >      var $this = $(this), size = $this.attr('href'), toggle = $('.' + size);
> >      $this.toggle(function() {
> >          toggle.hide();
> >      }, function() {
> >          toggle.show();
> >      });
>
> > });
>
> > HTH
>
> > --Klaus- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

Reply via email to