Ticket #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: | |
| Blocking: | Blocked by: |
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
comment:2 Changed 3 years ago by addyosmani
- Keywords parentsUntil added
- Priority changed from undecided to low
- Status changed from new to closed
- Component changed from unfiled to selector
- Resolution set to invalid
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.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

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