How about

$("<input type='hidden'/>").attr({id:"myid",
name:"myname"}).val("foo").appendTo(this);

I think that would work although the way you have it would be faster.
Most elements you could just say $("<div/>") to create a new one but
in IE the input requires the type be set.  So you have to specify the
type in the inital jQuery call as shown above.

David

On Jan 25, 5:42 pm, "Matt Quackenbush" <[EMAIL PROTECTED]> wrote:
> Hello,
>
> When my form is submitted, I want to add a couple of hidden form fields to
> the DOM.  I know that I can accomplish the task like so:
>
> $("#myForm").submit(function() {
>    var str = "<input type='hidden' name='myname' id='myid' value='foo' />";
>    $(this).append(str);
>
> });
>
> But that just doesn't "feel" right to me.  Is there a .new() method or
> something that would allow me to create the new element and then use the
> other methods (e.g. .new("input:hidden").attr("id").val("myid") ) before
> doing the .append() ?  I'm not finding anything in the docs, so I'm guessing
> there is not; justwanted to check.
>
> Thanks,
>
> Matt

Reply via email to