Bug Tracker

Opened 8 years ago

Closed 8 years ago

#9515 closed feature (invalid)

el(.comma, .separated, .list):pseudo

Reported by: OP Owned by: OP
Priority: low Milestone: 1.next
Component: selector Version: 1.6.1
Keywords: Cc:
Blocked by: Blocking:

Description

Assuming this is the css code

div.class1.style, div.class2.style { background: red; }
*.style { background: blue; }

I was surprised that this would work (the comma separated list in the parenthesis)

$("div(.class1, .class2):parent").each(function(){
	$(this).addClass('style');
});

(basically selects all non empty div.classN elements)

But, this just doesn't do anything

$("div(.class1, .class2)").each(function(){
	$(this).addClass('style');
});

I am curious at to why?

Change History (5)

comment:1 Changed 8 years ago by Rick Waldron

Component: unfiledselector
Owner: set to OP
Status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a reduced jsFiddle test case to help us assess your ticket!

Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, I've created this boilerplate: http://jsfiddle.net/rwaldron/da3nM/ Open the link and click to "Fork" in the top menu.

comment:2 Changed 8 years ago by OP

Status: pendingnew

http://jsfiddle.net/geVsk/

Oh it seems that in the first case (.class1, .class2) jQuery just ignores the stuff parenthesis and in the second it ignores everything... I've just tested it on my PC too and works the same... I guess I didn't test it thoroughly the first time...

So maybe I could rephrase the original question to:

Could we add the parenthesis sel(sel, sel, sel)sel as a selector meaning select all in the comma separated list?

comment:3 Changed 8 years ago by ajpiano

It's unclear to me what you intend for this "selector" to do? There are a number of pseudoselectors that accept a comma-delimited list of selectors - :not(), :has(), etc - in addition to jQuery() itself. The suggestion you've made here, however, is quite vague - does it work like .find()? .filter()? This may be a case of the combination of misunderstanding how selectors (including the :parent pseudo) are intended to work (more or less like CSS - where there is no "parenthesis selector") - and the library handling completely unexpected input in an unexpected way. Turning that into a selector-based alias for filter as a feature doesn't seem like a wise idea to me.

I'd suggest instead just doing $("div").filter(".class1, .class2").whatever();

Thanks for your time and interest in helping out the jQuery project!

comment:4 Changed 8 years ago by OP

Yeah I meant () (I dubbed it "parenthesis selector" :P ) to be as a selector alias for filter() but if you don't think its a good idea I have no problems with it not happening

comment:5 Changed 8 years ago by dmethvin

Priority: undecidedlow
Resolution: invalid
Status: newclosed

We definitely want to stick with standard CSS selectors so that jQuery can take advantage of the native querySelectorAll methods. I really do wish CSS4 adds some sort of parenthesized operator as well though, it would be mighty handy at times.

Note: See TracTickets for help on using tickets.