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 <dave.meth...@gmail.com> 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("#field2").length
>
>  // If elements are selected in this jQuery object,
>  // add sel to that; else empty the object.
>  jQuery.fn.and = function(sel){
>     return this.length? this.add(sel) : this.pushStack([]);
>  };
>
>  // If no elements are selected in this jQuery object, use
>  // the ones selected by sel; else use the current ones.
>  jQuery.fn.or = function(sel){
>     return this.pushStack( this.length? this : sel );
>  };
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to