[jQuery] Re: hiding a div when another div becomes empty?
$('#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: > > hidden items > ...links... > > any ideas on how i would do it?
[jQuery] Re: hiding a div when another div becomes empty?
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: > > > hidden items > > ...links... > > > any ideas on how i would do it?
[jQuery] Re: hiding a div when another div becomes empty?
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: > > > > hidden items > > > ...links... > > > > any ideas on how i would do it?
[jQuery] Re: hiding a div when another div becomes empty?
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: > > > > > hidden items > > > > ...links... > > > > > any ideas on how i would do it?
[jQuery] Re: hiding a div when another div becomes empty?
ok, thank you, makes perfect sence now... On May 21, 1:34 pm, Wizzud <[EMAIL PROTECTED]> wrote: > 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: > > > > > > hidden items > > > > > ...links... > > > > > > any ideas on how i would do it?