The bahaviour of append(), prepend() etc. method and $.create() from
this plugin is slightly different. Those methods allows you to modify
DOM tree but when you want to add something to that tree you need to
create a DOM element before insterting it to the tree. The only option
jQuery leaves you to do that is by typing HTML code as a method
argument, which is IMO ugly. You can easily mistype HTML, and I
believe it's a good practice to separate JS and HTML code completely.
Let me give an example.
Lets suppose you want to create a simple select-box in JS with two
options and one of them selected. Plus you want to add some id and
name to the select box. The new element should be inserted to
div#myDiv
If you choose pure jQuery approach you will write something like:
$('div#myDiv').append('<select name="myName" id="mySelect"><option
value="opt1">optText1</option><option value="opt2"
selected="selected">optText2</option></select>');
However using this plugin you can achieve the very same effect in a
bit prettier way I believe:
var children = [$.create('option', {value: 'opt1'}, 'optText1'),
$.create('option', {value: 'opt2', selected: 'selected'},
'optText2')];
$('div#myDiv').append($.create('select', {name: 'myName', id:
'mySelect'}, children));
Another case where this plugin gives you benefits from just using core
jQuery library is when you need to create a DOM element but you don't
want it to be placed into DOM tree. A good example of that could be
unit tests. Some times you may need to create an element, perform some
oprations on it in order to make sure your JS works as it supposed to
work, but not necessarily you wan't this element to be inserted into
the page displaying test results because then you will need to
remember to remove it after tests are complited. jQuery doesn't give
you any methods that could create new elements without inserting them
to the document tree and the only option you are left is using JS
document.createElement() method, but then it would be very difficult
to create more complex structures, adding attributes and children.
Anyway, I don't believe my plugin to be a MUST-HAV. It just simplifies
some of the common tasks with dynamic element creation I had to
perform while writing my JS apps.