On Sep 12, 2007, at 5:50 PM, Glen Lipka wrote:
Shouldn't it be child() and children() if we have parent() and parents()?
I feel like we are mangling plural/singular rules.


I don't think so. As Richard pointed out, you can have more than one direct child (one level down) but you can only ever have one parent. My vote was for using ancestors() instead of parents(), since it's semantically more correct. But I didn't win that one. ;-)

If we were going with a purely DOM-based nomenclature, then it would make the most sense (to me, anyway) to have .parent() and .ancestors () going up the DOM and .children() and .descendants() going down the DOM. I'm not suggesting that we change to that, though. People seem to learn the labels pretty quickly and usually have an easy time remembering what they do once they learn them.

Here is something interesting, though: .parent(), .parents(), and .children() can all be used without any parameters, but .find() can't. You'd have to do .find('*'). Well, maybe it isn't so interesting. Anyway, just thinking out loud here. Carry on. :-)


--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com



On Sep 12, 2007, at 5:50 PM, Glen Lipka wrote:

Shouldn't it be child() and children() if we have parent() and parents()?
I feel like we are mangling plural/singular rules.

Glen

On 9/12/07, Richard D. Worth <[EMAIL PROTECTED]> wrote:

On 9/12/07, Glen Lipka <[EMAIL PROTECTED] > wrote:
I am confused. Why aren't the grandchildren being included in the call for children()? Using $("#content *") gets all the grandkids. I thought parents() gets all the grandparents. Is children different?

$("#content").children() is equivalent to $("#content > *")

children() is a little more analogous to parent() than parents(). parent() moves the selection up one level (always 1 element, except for document/root), children() moves it down one level (0, 1, or more elements).

One reason they might be/seem different is parent elements can have 0-many children, but children have at most 1 parent. So it makes sense to have a parent() that selects 0 or 1, and a parents() that returns 0 to many (all ancestors, in order from first parent to top- level/oldest ancestor). Then parents(':first') == parent().

For all descendants, you can do .find("*").

- Richard



Reply via email to