> 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
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
> 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
> > $("#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
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")
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
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
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
> $("#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
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
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
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.
>
>
12 matches
Mail list logo