Skip to main content

Bug Tracker

Side navigation

#4095 closed enhancement (invalid)

Opened February 09, 2009 11:03AM UTC

Closed November 18, 2010 03:07AM UTC

Last modified May 15, 2011 07:29PM UTC

Can't find body direct child nodes with external html source.

Reported by: Bastes Owned by:
Priority: major Milestone:
Component: core Version: 1.3.1
Keywords: Cc:
Blocked by: Blocking:
Description

(tried with Firefox 3.0.6, using jRails )

Exemples :

$('div', '<html><body><div>blah</div></body></html>');

> []

$('div', '<html><body><div><div>blah</div></body></html>');

> ['<div>blah</div>']

Tried with a wide variety of elements and selectors, it seems elements located just under the body are never matched using specific html source.

Attachments (0)
Change History (6)

Changed February 09, 2009 11:04AM UTC by Bastes comment:1

Exemples :

$('div', '<html><body><div>blah</div></body></html>');

> []

$('div', '<html><body><div><div>blah</div></body></html>');

> [ <div>blah</div> ]

Changed February 10, 2009 01:15AM UTC by dmethvin comment:2

The expression:

$('div', '<html><body><div>blah</div></body></html>');

is equivalent to:

$('<html><body><div>blah</div></body></html>').find('div');

HTML strings are processed in jQuery by using the

.innerHTML
property, which does not seem to allow
<html>
or
<body>
tags. So, the html there is effectively reduced to
<div>blah</div>
and the
.find('div')
does not find another div below this context.

Changed February 10, 2009 03:38PM UTC by john comment:3

component: selectorcore
owner: john
priority: blockermajor
type: bugenhancement
version: 1.2.61.3.1

Two things need to happen here:

1) We need to unify how we handle this serialization across browsers. I think that if a <body> exists we make sure that we only tackle what's inside of it.

2) We document how exactly this parsing works - and be sure to emphasize that we only grab what's in the body.

So while this won't solve this bug in question, it will make it easier for others to understand.

Changed July 15, 2009 08:33AM UTC by yehuda comment:4

milestone: 1.3.21.3.3

Changed November 18, 2010 03:07AM UTC by dmethvin comment:5

keywords: → needsdocs
milestone: 1.4
resolution: → invalid
status: newclosed

The API docs need to be updated to clarify the behavior, we cannot change it since it's inherent to the .innerHTML implementations. Some of this could be reused:

jQuery uses the browser's .innerHTML property to parse the retrieved document and insert it into the current document. During this process, browsers often filter elements from the document such as <html>, <title>, or <head> elements. As a result, the elements retrieved by .load() may not be exactly the same as if the document were retrieved directly by the browser.

http://api.jquery.com/load/

Marked as needsdocs for later update.

Changed May 15, 2011 07:29PM UTC by addyosmani comment:6

keywords: needsdocs