[jquery-dev] Re: And-Selector?

2009-02-11 Thread Dave Methvin
> Couldn't you just do: > > jQuery.fn.and = function(sel){ >    return this.length? this.add(sel) : jQuery([]); > }; You would lose the ability to use .end() to get back to the previous object. Since .add() does a pushStack you would want the other case to do one too to keep the previous object c

[jquery-dev] Re: And-Selector?

2009-02-10 Thread David Zhou
Couldn't you just do: jQuery.fn.and = function(sel){ return this.length? this.add(sel) : jQuery([]); }; -- dz On Tue, Feb 10, 2009 at 8:57 PM, Dave Methvin wrote: > >> If you want to work on the elements, though, the .and() >> plugin will return either [] or [#field1, #field2] >> to the c

[jquery-dev] Re: And-Selector?

2009-02-10 Thread Dave Methvin
> If you want to work on the elements, though, the .and() > plugin will return either [] or [#field1, #field2] > to the chain. Not true! It will return either [], [#field1], or [#field1, #field2] so it probably wouldn't help Jörn. Duh. --~--~-~--~~~---~--~~ You r

[jquery-dev] Re: And-Selector?

2009-02-10 Thread Dave Methvin
> > $("#field1").and("#field2").length > Wouldn't that be essentially the same as $("#field1, #field2").length > == 2 ? Yes, if you just wanted to know if both were there, a check for the length would be sufficient. If you want to work on the elements, though, the .and() plugin will return eith

[jquery-dev] Re: And-Selector?

2009-02-10 Thread jay
If you didn't know the length beforehand something like this would work: var sel = "#field1, #field2, #field3"; if($(sel).length == sel.split(',').length){ ... } A plugin or custom selector may be able to simplify it more. On Feb 8, 10:35 pm, Dave Methvin wrote: > > $("#field1 & #field2")

[jquery-dev] Re: And-Selector?

2009-02-09 Thread Ricardo Tomasi
But you already know the length you want beforehand, what's the difference? On Feb 9, 5:05 pm, David Zhou wrote: > That would return a boolean value, not the length. > > -- dz > > On Mon, Feb 9, 2009 at 1:59 PM, Ricardo Tomasi wrote: > > > Wouldn't that be essentially the same as $("#field1, #f

[jquery-dev] Re: And-Selector?

2009-02-09 Thread David Zhou
That would return a boolean value, not the length. -- dz On Mon, Feb 9, 2009 at 1:59 PM, Ricardo Tomasi wrote: > > Wouldn't that be essentially the same as $("#field1, #field2").length > == 2 ? > > On Feb 9, 1:35 am, Dave Methvin wrote: >> > $("#field1 & #field2").length would be either 0 or

[jquery-dev] Re: And-Selector?

2009-02-09 Thread Ricardo Tomasi
Wouldn't that be essentially the same as $("#field1, #field2").length == 2 ? On Feb 9, 1:35 am, Dave Methvin wrote: > > $("#field1 & #field2").length would be either 0 or 2, but never 1. > > How about a plugin? These are short enough they could be added to the > core. > > $("#field1").and("#fiel

[jquery-dev] Re: And-Selector?

2009-02-08 Thread Dave Methvin
> $("#field1 & #field2").length would be either 0 or 2, but never 1. How about a plugin? These are short enough they could be added to the core. $("#field1").and("#field2").length // If elements are selected in this jQuery object, // add sel to that; else empty the object. jQuery.fn.and = fu

[jquery-dev] Re: And-Selector?

2009-02-08 Thread David Zhou
That would be pretty sweet. But in the mean time, Jorn, maybe you could use something like: jQuery.fn.ifFound = function(condition) { return (this.length === condition)?this:jQuery([]); } So you could do $('#field1, #field2').ifFound(3).length -- dz On Sun, Feb 8, 2009 at 5:39 AM, Daniel

[jquery-dev] Re: And-Selector?

2009-02-08 Thread Daniel Friesen
Jörn Zaefferer's idea is basically '#field1 & #field2' is similar to the comma but not the same. '#field1, #field2' If neither #field1 nor #field2 exist use 0, if one of them exists use that one, if both exist use both. The difference is: '#field1 & #field2' If neither #field1 nor #field2 exist

[jquery-dev] Re: And-Selector?

2009-02-08 Thread Morgan Allen
is this different from $('#field1, #field2')? On Sun, Feb 8, 2009 at 2:03 AM, Jörn Zaefferer < joern.zaeffe...@googlemail.com> wrote: > > Is it possible to implement a and-selector with Sizzle? Say, something > like this: > > $("#field1 & #field2").length would be either 0 or 2, but never 1. > >