Bug Tracker

Opened 11 years ago

Closed 10 years ago

#11253 closed bug (duplicate)

:parent selector description is unclear/misleading

Reported by: Chealer Owned by:
Priority: low Milestone: None
Component: selector Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:


The description of the :parent selector reads: Select all elements that are the parent of another element, including text nodes.


Suppose you have: <div> <p id="secret">jQuery is evil!</p> </div>

It is not clear what jQuery("p:parent") matches. Does it match the div, i.e. the paragraph's parent? Or does it match the paragraph?

The answer is that :parent matches the paragraph. This can be deducted from observation of other selector constructs and the realization that a selector doing the former would be :parent(p), but this is far from obvious. It is not clear that :parent means "is a parent", but not "the parent of". Some have even suggested to rename the selector in the documentation comments. I don't know if this is desirable, but kk and Jakub Konecki suggested ":hasChild" and ":isParent". I did find it very surprising to read that ":parent"'s opposite was ":empty".

Furthermore, the current description implies that text nodes are elements, which is misleading.

A description which would fix both issues would be: Select all elements that have a child node (either an element or text).

Change History (2)

comment:1 Changed 11 years ago by timmywil

Component: unfiledselector
Keywords: needsdocs added
Priority: undecidedlow
Status: newopen


comment:2 Changed 10 years ago by timmywil

Keywords: needsdocs removed
Resolution: duplicate
Status: openclosed
Note: See TracTickets for help on using tickets.