On Aug 6, 2:41 pm, "Richard D. Worth" <rdwo...@gmail.com> wrote:
> On Thu, Aug 6, 2009 at 9:27 AM, Joshua Beall <joshbe...@gmail.com> wrote:
>
> > On Aug 6, 8:26 am, "Richard D. Worth" <rdwo...@gmail.com> wrote:
> > > You can include the pseudo-selector in the same selector, immediately
> > after
> > > the ID, like so:
>
> > > $("#myDiv:hidden").show();
> > > $("#myDiv:visible").hide();
>
> > > Another option would be to use the filter method:
>
> > > $("#myDiv").filter(":hidden").show();
> > > $("#myDiv").filter(":visible").hide();
>
> > That works--I had assumed that if I called something like $
> > ("#myDiv:hidden").show(); when myDiv is visible, it would cause a
> > problem "object not found" problem since #myDiv:hidden" should return
> > nothing, and I then tried to call ".show()" on that "nothing" that was
> > returned.
>
> It doesn't return nothing, it returns a jQuery object with 0 elements. Any
> method you call will do a .each (like a for loop) on that (empty) set, (not)
> calling that method on 0 elements. In other words, that loop will never even
> be entered.
>
>
>
> > In Java/C# I would get a NullReferenceException if I tried something
> > like this.  That's where I do most of my development so that's what I
> > was expecting.
>
> Annoying, huh? ;)
>
>

Annoying indeed :-)

Thanks for the explanation, Richard!

  -Josh

Reply via email to