rgvcorley rgvcorley - 1 year ago 106
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...

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download