Opened 13 years ago
Closed 12 years ago
#5870 closed bug (invalid)
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)
Change History (3)
Changed 13 years ago by
Attachment: | exists.htm added |
---|
comment:1 Changed 13 years ago by
$(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():
comment:2 Changed 12 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
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.
sample html