Modify ↓
Ticket #6053 (closed bug: invalid)
Cannot use unconnected dom nodes as context
| Reported by: | dwt | Owned by: | |
|---|---|---|---|
| Priority: | Milestone: | 1.4.2 | |
| Component: | ajax | Version: | 1.4.1 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
$ var a = $('<div id="bar" />')
$ a.get()
> [<div id="bar">]
$ a.is('#bar')
> true
$ $('#bar', a).get()
> []
> $('#bar', a.get()).get()
> []
This should work. It would also make unit testing without actually stuffing something into the dom much easier (and faster as it would prevent the browser redraws).
Change History
comment:2 Changed 3 years ago by john
- Status changed from new to closed
- Resolution set to invalid
You need to understand that $('#bar', a) is equivalent to doing: a.find("#bar") (as in, you're trying to find the #bar element inside of the 'a' element). It looks like you actually want: a.filter("#bar") (which will give you the results that only match the #bar selector.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
Note: See
TracTickets for help on using
tickets.

I just noticed that this works:
$ var a = $('<div><div id="bar" /></div>') $ $('#bar', a).get() > [<div id="bar">]Which is interesting. But would seem to pin the error to jquery not being able to find the context element itself?
Is that intentional?