DOM Elements Creator is a simple plugin for creating DOM elements on-a-fly which can be used as part of jQuery statements.
When you want to create new DOM element in pure jQuery you must use document.createElement() method and then new element must be wrapped in $() before it can be used in jQuery context. You can also use HTML code as a selector to create a new object but this way requires writing HTML, which is rarely comfortable. And you must also remember to espace any quotes. This plugin provides more elegant way to achieve the same effect and requires writting less code.
document.createElement()
$()
Just import plugin file after importing the jQuery library and you’re set.
$.create(element[, attributes[, children]])
element
attributes
children
var div = document.createElement('div'); $(div).attr('id', 'myId').text('myText').appendTo('#myElem');
$('<div>').attr('id', 'myId').text('myText').appendTo('#myElem');
or
$('<div id="myId">myText</div>').appendTo('#myElem');
$.create('div', {'id': 'myId'}, 'myText').appendTo('#myElem');
Plugin function was renamed from $.new to $.create to fix issues on Internet Explorer.
$.new
$.create