Bug Tracker

Modify

Ticket #3409 (closed bug: invalid)

Opened 6 years ago

Last modified 3 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:

Description

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 6 years ago by flesler

  • Cc Just, flesler added
  • Owner set to john

comment:2 Changed 6 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 6 years ago by Just

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

comment:4 Changed 5 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:

 http://docs.jquery.com/Core/jQuery#htmlownerDocument

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 3 years ago by snover

#7784 is a duplicate of this ticket.

comment:6 Changed 3 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:

 http://benalman.com/projects/jquery-misc-plugins/#htmldoc

comment:7 Changed 3 years ago by ajpiano

#10222 is a duplicate of this ticket.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.