#1888 closed bug (fixed)
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/>")
Attachments (1)
Change History (3)
comment:1 Changed 15 years ago by
Component: | core → ajax |
---|
comment:2 Changed 15 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note: See
TracTickets for help on using
tickets.
Fixed in [4062]. It was fixed when #1039 and #1733 were fixed.