Actually I was just thinking about this and I'm not positive which is faster either but I think not using attr would be. And I'm not sure the speed difference is significant, so take all this with a grain of salt. :)
It might actually depend on what type of element is being created too. Some really have to go through the jQuery.clean() function like an <input type="hidden"/> or a <tr> but a div might be faster to just do $(document.createElement("div")).attr(...); Again I'm not sure the speed difference is significant in most cases. These are all just gut feelings at this point since I haven't done the tests. David On Jan 26, 7:17 am, Karl Swedberg <[EMAIL PROTECTED]> wrote: > On Jan 25, 2008, at 10:13 PM, David Serduke wrote: > > > > > How about > > > $("<input type='hidden'/>").attr({id:"myid", > > name:"myname"}).val("foo").appendTo(this); > > > I think that would work although the way you have it would be faster. > > Most elements you could just say $("<div/>") to create a new one but > > in IE the input requires the type be set. So you have to specify the > > type in the inital jQuery call as shown above. > > Hey David, > > Very interesting that the way you mention above is not as fast as > putting in the whole HTML string at once. In our books, Jonathan > Chaffer and I chose to build new elements the "slower" way -- > with .attr({}) -- to make the code more readable and to keep it closer > to the "DOM Scripting" ideal, but I hadn't tested comparative speeds, > assuming that there wouldn't be much of a performance hit. > > --Karl > _________________ > Karl Swedbergwww.englishrules.comwww.learningjquery.com