Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
161
rated 0 times [  164] [ 3]  / answers: 1 / hits: 27737  / 13 Years ago, thu, february 23, 2012, 12:00:00

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>');
$form.attr('action',options.action);
}


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


More From » jquery

 Answers
33

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


[#87266] Wednesday, February 22, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
yusuf

Total Points: 167
Total Questions: 97
Total Answers: 108

Location: North Korea
Member since Tue, Jun 16, 2020
4 Years ago
;