Skip to main content

Bug Tracker

Side navigation

#5870 closed bug (invalid)

Opened January 19, 2010 07:50PM UTC

Closed October 08, 2010 01:33AM UTC

Specifying context fails for selector when context is a wrapped string

Reported by: tvanfosson Owned by:
Priority: minor Milestone: 1.4
Component: core Version: 1.4
Keywords: context selector Cc:
Blocked by: Blocking:
Description

When checking a string for the existence of an element by specifying the string as a wrapped jQuery as the context, the selector fails.

var html = '<div>test</div>';

var exists = $('div', $(html)).length > 0;

This code results in exists === false, when clearly the the string contains a valid divelement.

Yet, if the element is added to the document (when it previously contained no divs), it does properly find the element

$('body').append(html);

var exists2 = $('div').length > 0;

Attachments (1)
  • exists.htm (0.4 KB) - added by tvanfosson January 19, 2010 07:51PM UTC.

    sample html

Change History (2)

Changed January 20, 2010 02:21AM UTC by dmethvin comment:1

$(x,y)
is equivalent to
$(y).find(x)
.

So,

$('div', $('<div>test</div>'))
is the same as
$(<div>test</div>).find('div')
.

The

.find()
method looks *below* the nodes provided. There are no
div
elements *contained* in the context. See the documentation for jQuery(), .find(), and .filter():

http://api.jquery.com/jQuery/

Changed October 08, 2010 01:33AM UTC by addyosmani comment:2

resolution: → invalid
status: newclosed

Invalid: I believe the explanation offered by dmethvin satisfactorily explains why this particular bug isn't actually a valid jQuery core issue.

Further information regarding your original concerns can be addressed by looking at the API documentation site as previously suggested.

Closing as there has been no further activity on this ticket for a long time and it appears to have been resolved.