The difference of the multi-selector syntax vs. the extended selector
should be pointed out, in case it's not immediately apparent. From the
OP's original request:

$("*[name='someName'][value='someValue'||'someOtherValue']");

in multi-selector syntax this would actually be:

$("[name=someName][value=someValue],[name=someName]
[value=otherValue]");

so the name=someName has to be repeated for each value. It's more
friendly than this

$("*[name='someName'][value='someValue']").add("*[name='someName']
[value='someOtherValue']");

but still suffers from having to repeat the name=someName portion.


On Apr 25, 3:41 am, Ricardo <ricardob...@gmail.com> wrote:
> http://lmgtfy.com/?q=extend+jquery+expressions
>
> As an alternative, you can use the normal multi-selector syntax (comma
> separated):
>
> $("[name=someName][value=someValue],[name=otherName]
> [value=otherValue]");
>
> On Apr 24, 10:07 pm, barton <bartonphill...@gmail.com> wrote:
>
> > That is very interesting, can you explain it a bit. I can't find any
> > documentation on jQuery.expr[":"] -- I can find it in the code but
> > don't really understand what/how it does/works. jQuery.expr[":"] =
> > jQuery.expr.filters; but now I'm really lost.
>
> > On Apr 24, 6:13 pm, mkmanning <michaell...@gmail.com> wrote:
>
> > > You can always create your own selector:
> > > jQuery.extend(jQuery.expr[':'], {
> > >     'values': function(a,i,m) {
> > >                 return a.value && $.inArray(a.value,m[3].split(','))!=-1;
> > >     }
>
> > > });
>
> > > Use like:
> > > $('input[name=fooA]:values(foo1,foo4)');
>
> > > On this markup it returns the first and last inputs:
> > > <input type="text" name="fooA" value="foo1" />
> > > <input type="text" name="fooB" value="foo2" />
> > > <input type="text" name="fooA" value="foo3" />
> > > <input type="text" name="fooB" value="foo4" />
> > > <input type="text" name="fooA" value="foo4" />
>
> > > On Apr 24, 4:22 pm, machineghost <machinegh...@gmail.com> wrote:
>
> > > > Hello,
>
> > > > I already know that you can combine multiple attribute selectors, &&-
> > > > style, by doing:
> > > > $("*[name='someName'][value='someValue']");
>
> > > > However, what I was wondering is, is there any way to combine multiple
> > > > attribute selectors, ||-style, such that I could select:
> > > > $("*[name='someName'][value='someValue']").add("*[name='someName']
> > > > [value='someOtherValue']");
> > > > with a single select?  I'm imagining a syntax of something like:
> > > > $("*[name='someName'][value='someValue'||'someOtherValue']");
> > > > (but, obviously, that syntax doesn't work).
>
> > > > The repetition of "[name='someName']" seems unnecessary to me, but I
> > > > can't figure out any way to get around it without an "or value=" type
> > > > selector.  Any help would be appreciated (even if it's just "no you
> > > > can't do that, go bug the developers" ;-)).
>
> > > > Jeremy

Reply via email to