Skip to main content

Bug Tracker

Side navigation

#12889 closed feature (plugin)

Opened November 13, 2012 10:36PM UTC

Closed November 13, 2012 11:42PM UTC

Last modified November 14, 2012 01:14AM UTC

Add .cousin() support

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

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

Attachments (0)
Change History (3)

Changed November 13, 2012 10:47PM UTC by anonymous comment:1

Example... I have a structure like:

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

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

Changed November 13, 2012 11:42PM UTC by ajpiano comment:2

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

Changed November 14, 2012 01:14AM UTC by dmethvin comment:3

Agreed.