Bug Tracker

Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#7430 closed bug (invalid)

about parentsUntil()

Reported by: liangyongning@… 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>

Change History (2)

comment:1 Changed 9 years ago by jitter

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

comment:2 Changed 9 years ago by addyosmani

Component: unfiledselector
Keywords: parentsUntil added
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.

Note: See TracTickets for help on using tickets.