Side navigation
#9603 closed enhancement (invalid)
Opened June 16, 2011 12:44PM UTC
Closed June 23, 2011 11:02PM UTC
Last modified May 09, 2013 01:22PM UTC
Give siblings() the option to provide siblings which are not part of itself.
Reported by: | niklas | Owned by: | niklas |
---|---|---|---|
Priority: | low | Milestone: | 1.next |
Component: | traversing | Version: | 1.6.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Currently, using siblings() on a selection which contains multiple elements under the same parent, will return all elements under the parent.
With the following markup:
<ul> <li>1</li> <li class="select">2</li> <li class="select">3</li> <li>4</li> </ul>
Using
$('ul li.select').siblings().length;
Would return all 4 elements.
Instead, I propose that the siblings should have a second optional boolean variable which would define whether to select only the siblings which aren't part of the selection the method is applied on. That can easily be done with a custom plugin like this:
(function( $ ){ $.fn.uniqueSiblings = function(selector) { return $(this).siblings(selector).not(this); }; })( jQuery );
But considering how little code it is, why doesn't jQuery have such functionality by default? Personally, I think it is the more logical way for siblings to work for selections with multiple elements anyway, but with providing a boolean variable to choose which way (old way or, this new proposed way) it will continue to work for users like before.
Working test case (using same example as on official siblings() documentation): http://jsfiddle.net/niklasvh/Ax63q/
Attachments (0)
Change History (4)
Changed June 20, 2011 02:06AM UTC by comment:1
component: | unfiled → traversing |
---|---|
owner: | → niklas |
priority: | undecided → low |
status: | new → pending |
Changed June 20, 2011 02:43PM UTC by comment:2
status: | pending → new |
---|
If you want to do something to the selection, and something that isn't part of the selection, you'd have to do it in 2 different statements, where as with siblings you could first apply it to the selection, and then apply to the rest.
What about element collections which cannot be (easily) described with selectors, if they were composed using add() for example?
Replying to [comment:1 dmethvin]:
Why not$("ul>li:not(.selected)")
instead? I'll leave this open for a reply, but I would not want to have.siblings
add a special-case boolean argument for a case like this.
Changed June 23, 2011 11:02PM UTC by comment:3
resolution: | → invalid |
---|---|
status: | new → closed |
Sorry but I'm not understanding the need here. Perhaps you can explore and discuss it in the forum, then formulate a specific request if there is interest.
Changed May 09, 2013 01:22PM UTC by comment:4
I have the same problem. Why closed?
sibling for me is : all but not selected.
My sample :
editors = $('#jform_editor').find(render.editors); editors.show().siblings().hide();
editors is the list of valid editor for eg: ".text,.textarea".
and i hide the other. IN my case sibbling is all unvalid editor. But this simply remove all, because sibbling work only in one element.
Perhaps a new jQuery().sibblings() ?
Why not
$("ul>li:not(.selected)")
instead?I'll leave this open for a reply, but I would not want to have
.siblings
add a special-case boolean argument for a case like this.