Dojo 1.3 now available. Looks like an excellent release. dojo.create is particularly nice—I’d be interested to know why something similar has never shipped with jQuery (presumably there’s a reason) as it feels a lot more elegant than gluing together an HTML-style string. Also interesting: you can swap between Dojo’s Acme selector engine and John Resig’s sizzle.
Hey Simon you can create dom elements in that manner in jQuery like so:
$('<div>').addClass('loading').append($('<a>').att r('href','#'));
Clint Ecker - 1st April 2009 00:50 - #
Oops, missed the "with attributes" bit—was that what you were referring to?
Clint Ecker - 1st April 2009 00:51 - #
I find the angle bracket notation pretty unintuitive. It looks like there's innerHTML manipulation going on. In fact, jQuery uses a regex to detect single elements and converts it to a createElement call under the hood, but you have to dig pretty far in to the code to spot that. Probably just a colour-of-the-bike-shed issue.
I've always used Michael Geary's Easy DOM Creation plugin.
http://mg.to/2006/02/27/easy-dom-creation-for-jque ry-and-prototype
The cool part for me is the nesting, and the ability to assign a variable to any element in the tree you're creating for use later.
Paul McLanahan - 1st April 2009 15:40 - #
I agree with Paul. Creating nested DOM elements is much easier the jQuery way and I think it is more intuitive than having .create() function IMO.
jQuery Tutorials - 23rd April 2009 13:23 - #