Ticket #4914 (closed bug: invalid)
IE8 error when creating a form
| Reported by: | jeremywoertink | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | 1.4 |
| Component: | core | Version: | 1.3.2 |
| Keywords: | IE8, form, create new form element | Cc: | |
| Blocking: | Blocked by: |
Description
When creating a form element, you can't specify attributes for the form while creating the form. The attributes must be assigned after the form has already been created. You can test this in the IE8 console like this.
var form = $('<form action="index.html">');
{...}
$(form).length
0
var form = $('<form>');
{...}
$(form).attr('action', 'index.html');
{...}
$(form).length
1
I have not tested this in other versions of IE, but I'm pretty sure it doesn't work in the others as well.
Change History
comment:3 in reply to: ↑ 1 Changed 4 years ago by jeremywoertink
odd that it would work like that since doing
var div = $('<div>'); alert($(div).length);
notice no close tag on the div. This works with every other element that I've tried it on (i.e. table, span, p, div, tr, td)
I guess if it's not a bug, then oh well. Thanks for the info. I tested that in IE8 and it does seem to work.
~Jeremy
Replying to Larry Battle:
I don't think that's a bug. When creating elements you have to use the close tag. <form/> or <form></form>
var form = $('<form action="index.html"/>'); alert( "$(form).length = " + $(form).length ); alert( "$(form).attr( 'action' ) = " + $(form).attr( 'action' ) );Works on IE6 and other browsers, but I'm not sure about IE8.
example: http://jsbin.com/uqomo
comment:4 Changed 4 years ago by dmethvin
- Status changed from new to closed
- Resolution set to invalid
IE's HTML parser is picky sometimes. Always close your tags. Self-closing tags are handled internally by jQuery for situations where there are no attributes, such as "<div />" but for your case you'd need a closing tag.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

I don't think that's a bug. When creating elements you have to use the close tag. <form/> or <form></form>
var form = $('<form action="index.html"/>'); alert( "$(form).length = " + $(form).length ); alert( "$(form).attr( 'action' ) = " + $(form).attr( 'action' ) );Works on IE6 and other browsers, but I'm not sure about IE8.
example: http://jsbin.com/uqomo