It's just usage.
'$this' is commonly used to indicate that the variable holds the
jQuery object of 'this'. Personally I tend not to use variable names
beginning with '$' because it confuses me, but a lot of people do, and
that tends to be the convention they use, ie.
var $this = $(this);
var $elem = $(elem);
var $me = $(me);
etc,etc.

In your particular code, you were setting...
var $this = $(this).attr('class');
...which puts a string into $this, so $this is not a jQuery object,
and *might* be more conventionally written...
var klass = $(this).attr('class'); //or whatever variable name you
choose

The only (very, very, very slight) advantage to my code is that it
saves converting 'this' into a jQuery object twice - once to find the
class, and then again to remove itself.


On May 21, 9:52 am, thekman <[EMAIL PROTECTED]> wrote:
> Hi Wizzud,
> Just wondering if there is any performance/browser compatibility or
> any other reason you changed:
>
> var $this = $(this).attr("class");
> $('#'+$this).show();
>
> to
>
> var $this = $(this);
> $('#'+$this.attr('class')).show();
>
> On May 21, 9:38 am, thekman <[EMAIL PROTECTED]> wrote:
>
> > Thank you Wizzud, works a treat...
>
> > On May 21, 9:26 am, Wizzud <[EMAIL PROTECTED]> wrote:
>
> > > $('#hiddenleft a').livequery('click', function() {
> > >     var $this = $(this);
> > >     $('#'+$this.attr('class')).show();
> > >     $this.remove();
> > >     if(!$('#hiddenleft a').length){
> > >       $('#hiddenleft,#hiddencontent').hide();
> > >     }
> > >  });
>
> > > On May 20, 3:52 pm, thekman <[EMAIL PROTECTED]> wrote:
>
> > > > Hi all,
> > > > I am removing links from a div when they are clicked on using the code
> > > > below:
>
> > > > $('#hiddenleft a').livequery('click', function() {
> > > >                 var $this = $(this).attr("class");
> > > >                 $('#'+$this).show();
> > > >                 $(this).remove();
> > > >  });
>
> > > > when all links are removed, i want hide that div & the div above it -
> > > > hiddencontent .
> > > > the links are displayed in the following divs:
>
> > > >   <div id="hiddencontent">hidden items</div>
> > > >   <div id="hiddenitems"><div id="hiddenleft">  ...links...</div></div>
>
> > > > any ideas on how i would do it?

Reply via email to