view raw
rgvcorley rgvcorley - 11 months ago 48
jQuery Question

Best way to create new DOM elements

Using jquery is it better to create a DOM element like this:-

function create(options)
$('<form action="' + options.action + '"></form>');

Or like this:

function create(options)
$form = $('<form></form>');

This may be a matter of opinion. I feel that the second way gives more clarity but I suspect it is less efficient...


jQuery can create object as following code

$form = $('<form>', {action: 'my action'});

class is a reserved word in IE and needs to be quoted. See full list of reserved words: Reserved Keywords in Javascript