Bug Tracker

Opened 11 years ago

Closed 9 years ago

Last modified 9 years ago

#4095 closed enhancement (invalid)

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.

Change History (6)

comment:1 Changed 11 years ago by Bastes

Exemples :

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

=> []

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

=> [ <div>blah</div> ]

comment:2 Changed 11 years ago by dmethvin

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.

comment:3 Changed 11 years ago by john

Component: selectorcore
Owner: john deleted
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.

comment:4 Changed 10 years ago by yehuda

Milestone: 1.3.21.3.3

comment:5 Changed 9 years ago by dmethvin

Keywords: needsdocs added
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.

comment:6 Changed 9 years ago by addyosmani

Keywords: needsdocs removed
Note: See TracTickets for help on using tickets.