Bug Tracker

Modify

Ticket #6053 (closed bug: invalid)

Opened 4 years ago

Last modified 4 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 4 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 4 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.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.