Bug Tracker

Ticket #3409 (closed bug: invalid)

Opened 7 years ago

Last modified 4 years ago

Can't get HEAD element from an AJAX return

Reported by: Just Owned by: john
Priority: major Milestone: 1.3
Component: core Version: 1.2.6
Keywords: Cc: Just, flesler
Blocking: Blocked by:


Using this <js>alert($('<html xmlns=" http://www.w3.org/1999/xhtml" xml:lang="en"><head><title>Test</title></head><body>InnerHTML\'s body</body></html>').html());</js>

It display me "Test". So the TITLE element's content. Can't get any one of the HTML, HEAD or BODY element. Can access the element in the BODY element but not those which is in the HEAD element.

Change History

comment:1 Changed 7 years ago by flesler

  • Cc Just, flesler added
  • Owner set to john

comment:2 Changed 7 years ago by Just

All the element is finally put "the one after the other". Just removing the HTML, HEAD, and BODY elements. so that html

<html xmlns=" http://www.w3.org/1999/xhtml" xml:lang="en"><head><title>Test</title></head><body>InnerHTML\'s body</body></html>

looks like this

<title>Test</title>InnerHTML\'s body

comment:3 Changed 7 years ago by Just

Under safari that mess up ! I can't get head element at all :/.

comment:4 Changed 7 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

You can't swallow a whole html document with $("html"); whatever you pass in as a string has to be valid within a div:


As an alternative, you could use an XML parser ouside of jQuery if the markup is valid XML and pass that to $() instead.

comment:5 Changed 5 years ago by snover

#7784 is a duplicate of this ticket.

comment:6 Changed 5 years ago by cowboy

FWIW, I've written a plugin called jQuery htmlDoc that attempts to address this issue. It probably needs more testing, but in my basic tests it works well:


comment:7 Changed 4 years ago by ajpiano

#10222 is a duplicate of this ticket.

Note: See TracTickets for help on using tickets.