Side navigation
#1888 closed bug (fixed)
Opened November 02, 2007 07:59PM UTC
Closed December 10, 2007 05:51PM UTC
Last modified October 08, 2009 11:57AM UTC
jQuery(string) create not valid DOM when string is html with newlines
Reported by: | lucifer4u | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 1.2.2 |
Component: | ajax | Version: | 1.2.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
It is common task to get html from server and to work with it in its own context.
I have test.html file with this content:
<html> <head> <title> Test page </title> </head> <body> <div> Some information </div> </body> </html>
So after trying
$.get("test.html",function(data){alert($(data).find("div");})
i found an error. Here is more info about:
Test examples:
var s1 = '<html><head><title>info</title></head><body><div>info</div></body></html>'; alert($(s1).find('div')); // [object Object] var s2 = '<html>\\n<head><title>info</title></head><body><div>info</div></body></html>'; alert($(s2).find('div')); // [error]
Solution:
function jquery_from_html(data) { return $("<moo/>").append(data); }
Example of usage:
$.get( "test.html", {}, function(data){ d = $("div#system", jquery_from_html(s)); alert(d.text()); }, "html" )
Found in jquery source in load function:
// Create a dummy div to hold the results jQuery("<div/>")