Bug Tracker

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#12889 closed feature (plugin)

Add .cousin() support

Reported by: anonymous Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.8.3
Keywords: Cc:
Blocked by: Blocking:


This would be shorthand for .parents().siblings().children()

Change History (3)

comment:1 Changed 10 years ago by anonymous

Example... I have a structure like:

   <span class="error">Name is erroneous</span>
   <input name="name" type="text"/>
   <input name="nameUnknown" type="checkbox"/> Unknown

I want to move the error into a tooltip to the right of the last input in the div. $(".error").cousins(":input").last() would be the most efficient way of finding this, or at least more so than $(".error").parent().siblings().children(":input").last() or $(".error").parent().next("div").children(":input").last()

comment:2 Changed 10 years ago by ajpiano

Resolution: plugin
Status: newclosed

Thanks for your time and interest in helping out with jQuery Core! Unfortunately, I can't see us adding this to the API surface. There's syntactic sugar, and then there's syntactic saccharin: overly concentrated sweetness that isn't really good for you anyway. The language of children, siblings, parents, etc. is codified in the DOM APIs, whereas "cousin" is just extending that metaphor in a nebulous way. As proposed, this method only gets "first cousins." What if people want second cousins, or fourth cousins twice-removed? This opens up a can of worms that I can't foresee us wanting to deal with.

In other words, this type of functionality or any other custom traversal methods are best reserved for a plugin at this point :)

comment:3 Changed 10 years ago by dmethvin


Note: See TracTickets for help on using tickets.