Bug Tracker

Opened 13 years ago

Closed 13 years ago

Last modified 11 years ago

#6061 closed bug (invalid)

jQuery won't find elements from ajax request data from within <head> tag

Reported by: mtajur Owned by:
Priority: Milestone: 1.4.2
Component: ajax Version: 1.4.1
Keywords: ajax, head, find Cc:
Blocked by: Blocking:


If you do a ajax request using $.get(), and the result coming from the server is a full, valid xHTML 1.0 Transitional document, jQuery fails to find elements from the result that are placed inside the <head> tag, neither does jQuery find the <head> tag itself.

Example: $(function() {

$.get('some.html', function(data) { alert( $(data).find('head').size() ); });


If some.html is a full xHTML page, with <head> tag and everything, this should result in alerting "1", but instead, jQuery finds neither <head> tag from the result nor any of the tags inside <head>.

In case I made any errors in the example, I'm sorry, but I've tested this with many working examples and asked a question about in on Stack Overflow (see http://stackoverflow.com/questions/2146594/how-to-replace-entire-css-of-a-page-after-an-ajax-request-with-jquery ) - no solutions so far. So it seems like a bug.

Change History (1)

comment:1 Changed 13 years ago by john

Resolution: invalid
Status: newclosed

Yep, that's correct - parsing straight HTML we only guarantee the contents of the body element. If you wish to access the XML of the page directly then I recommend that you explicitly make the file .xhtml or request it as XML, for example:

  $.ajax({ dataType: "xml", file: "some.html", success: function(data){ ... });
Note: See TracTickets for help on using tickets.