Skip to main content

Bug Tracker

Side navigation

#7430 closed bug (invalid)

Opened November 08, 2010 08:47AM UTC

Closed November 08, 2010 02:53PM UTC

Last modified March 15, 2012 12:37PM UTC

about parentsUntil()

Reported by: liangyongning@yahoo.com Owned by:
Priority: low Milestone: 1.5
Component: selector Version: 1.4.3
Keywords: parentsUntil Cc:
Blocked by: Blocking:
Description

something wrong with this function,

e.g.

I got a DOM like this

<div class=".box">

<div class=".box-inner">

<div>

<p id="text">Hello</p>

</div>

</div>

</div>

and

$('#text').parentsUntil('.box')

got a DOM Element is

<div class=".box-inner">...</div>

not

<div class=".box">...</div>

Attachments (0)
Change History (2)

Changed November 08, 2010 11:49AM UTC by jitter comment:1

There are some issues with the sample code you gave. But I'll come later to that.

If I understood you correctly you expected <div class=".box"> to be returned too by $('#text').parentsUntil('.box'). This isn't how parentsUntil works. The documentation states

>Get the ancestors of each element in the current set of matched elements, up to but not including the element matched by the selector.

So parentsUntil works correctly and returns the parents of #text up to but not including .box itself.

test case which shows parentsUntil works as expected.


Issues with your sample code:

The class names in your sample include a period (full stop). Is this intentional or just a typo in the sample code? Because if e.g. .box is really the class name you need to escape the period (be it in your jQuery selectors or in your CSS).

So $('#text').parentsUntil('.box') wouldn't even work because there is no element with classname box (note the missing period). It would need to look like $('#text').parentsUntil('.\\\\.box') because you need to escape the period as described in selectors documentation

Changed November 08, 2010 02:53PM UTC by addyosmani comment:2

component: unfiledselector
keywords: → parentsUntil
priority: undecidedlow
resolution: → invalid
status: newclosed

I believe that Jitter has covered the main issues in this ticket. Namely that parentsUntil doesn't function the way you thought (please see the documentation) and secondly, if you wish to use the code structure we see in your sample, you'll need to escape the periods as mentioned for the code to correctly function.