Bug Tracker

Opened 8 years ago

Closed 8 years ago

Last modified 7 years ago

#7456 closed bug (invalid)

jQuery removes body-element when parsing string with html or xml

Reported by: mekwall Owned by:
Priority: low Milestone: 1.5
Component: manipulation Version: 1.4.4rc
Keywords: Cc:
Blocked by: Blocking:

Description

When passing a string with well formed xml or html jQuery will remove any body-element, but leave all children nodes intact.

This can easily be reproduced by doing the following:

var xml = "<note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Why is it not hitting this?</body></note>";

console.log($('to, from, heading, body', xml));

Change History (7)

comment:1 Changed 8 years ago by mekwall

For the lazy, jsfiddle test case here: http://jsfiddle.net/mekwall/xKEqa/

comment:2 Changed 8 years ago by dmethvin

Resolution: invalid
Status: newclosed

There is no signature of jQuery() that accepts an xml string.

Last edited 8 years ago by dmethvin (previous) (diff)

comment:3 in reply to:  2 Changed 8 years ago by mekwall

Replying to dmethvin:

There is no signature of jQuery() that accepts an xml string.

Well I also stated normal html, not only xml. I've also noticed that it removes head as well as seen here: http://jsfiddle.net/mekwall/s2K2x/

Is there a reason for this behavior?

Edit: Also it's removing the html-element. What if you would want to access the attributes of these elements?

Last edited 8 years ago by mekwall (previous) (diff)

comment:4 Changed 8 years ago by dmethvin

Component: unfiledmanipulation
Keywords: needsdocs added
Priority: undecidedlow

I've marked this ticket needsdocs to have this paragraph from .load() converted to an "Additional Notes" entry and added to all applicable methods.

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/

comment:5 Changed 7 years ago by florian.assmann@…

When using a CUSTOM tag Instead of DIV the content still includes HTML, HEAD and BODY tags. Cheers Florian

comment:6 in reply to:  5 Changed 7 years ago by anonymous

Forget about what I said... :/

comment:7 Changed 7 years ago by addyosmani

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