Bug Tracker

Opened 6 years ago

Closed 6 years ago

#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:
Blocked by: Blocking:

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 (2)

comment:1 Changed 6 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 6 years ago by john

  • Resolution set to invalid
  • Status changed from new to closed

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.