:parent selector description is unclear/misleading #7

Closed
addyosmani opened this Issue Apr 19, 2012 · 1 comment

Projects

None yet

2 participants

@addyosmani
jQuery Foundation member

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).

Ticket: http://bugs.jquery.com/ticket/11253

@kswedberg
jQuery Foundation member

Duplicate of #57, which is fixed

@kswedberg kswedberg closed this Oct 16, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment