Now, this is only my opinion, and I'm not an expert by any means.

I believe that either of those methods would work.  It is possible that
there could be some minor performance difference between them.

jQuery creates a new element through the jQuery.clean method, which creates
a div element, adds it to the page, and then assigns its innerHTML property
with whatever you wrote.  It then extracts the childNodes of the div and
returns them wrapped in a jQuery object.

When you use the jQuery.fn.attr method, it goes through a series of steps to
assign the attributes you supplied.

I don't know which is faster.  Personally I assign my key attributes at the
time of creation, $('<input type="button" id="someid"'), but assign CSS
attributes afterwards $('<input type="button"
value="Submit").css({opacity:0.5});

JK

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Diego A.
Sent: Thursday, April 12, 2007 3:24 PM
To: jQuery (English)
Subject: [jQuery] Re: dynamic creation of an button


I didn't know that, but I do have a related question if you don't
mind.

I prefer to use...
$('<input type="button" id="some-id" value="yes">');
...instead of...
$('<input type="button">').attr({'id':'some-id', 'value': 'yes'});

It works fine, but so many people choose to use the second method.
Is there anything wrong with the way I do it?

On Apr 12, 10:30 pm, "Jeffrey Kretz" <[EMAIL PROTECTED]> wrote:
> Some of the attributes of a DOM object in IE are read-only.
>
> The "type" attribute is one of these and so cannot be assigned to AFTER
the
> element is created.
>
> JK
>
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
>
> Behalf Of spinnach
> Sent: Thursday, April 12, 2007 2:06 PM
> To: [EMAIL PROTECTED]
> Subject: [jQuery] dynamic creation of an button
>
> anybody knows why the following fails in ie, but works ok in firefox?
> $('<input>').attr({'type': 'button', 'id':'some-id', 'value': 'yes'})
>
> when i remove the type hash attribute, it works:
> $('<input type="button">').attr({'id':'some-id', 'value': 'yes'});
>
> dennis.


Reply via email to