Bug Tracker

Ticket #6053 (closed bug: invalid)

Opened 5 years ago

Last modified 5 years ago

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:1 Changed 5 years ago by dwt

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?

comment:2 Changed 5 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.

Note: See TracTickets for help on using tickets.