Ticket #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: | ||
| Blocking: | Blocked by: |
Description
The description of the :parent selector reads: Select all elements that are the parent of another element, including text nodes.
http://api.jquery.com/parent-selector/
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
comment:1 Changed 16 months ago by timmywil
- Keywords needsdocs added
- Priority changed from undecided to low
- Status changed from new to open
- Component changed from unfiled to selector
comment:2 Changed 9 months ago by timmywil
- Keywords needsdocs removed
- Status changed from open to closed
- Resolution set to duplicate
Ported to api issues: https://github.com/jquery/api.jquery.com/issues/57
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Ok