jquery - Mixing inline attributes with an attribute object -


i should 3 images here 2. last 1 fails:

<!doctype html> <html> <head> <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.5.1.js" type="text/javascript"></script> <script type="text/javascript"> $().ready(function() {     var img = $('<img src="icon.next.gif" url="/" />');     $("body").append(img);     img = $('<img />', { src: "icon.next.gif", url: "/" });     $("body").append(img);     var img = $('<img src="icon.next.gif" />', { url: "/" });     $("body").append(img); }); </script> </head>  <body> </body> </html> 

i swear i've mixed these before seems second parameter replaces tags. need add because i've got string generated (which comes inline attributes) , need add it.

here's [fiddle] who'd play it.

using ie9 , breaks with:

script438: object doesn't support property or method 'createdocumentfragment' jquery-1.5.1.js, line 5450 character 3

first, use $(document).ready(function(){ or shorthand $(function(){

secondly, remove url attribute third img , add slash before image src:

var img = $('<img src="icon.next.gif" url="/" />'); $("body").append(img); img = $('<img />', { src: "icon.next.gif", url: "/" }); $("body").append(img); img = $('<img src="/icon.next.gif" />'); $("body").append(img); 

as long you're pulling cdn, should try grab latest version of jquery before posting debug question, issue may have been resolved in jquery itself.

you're using 1.5.1. jquery on 1.6.2 now, fyi.

http://jsfiddle.net/x2qsz/2/


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -