Bug Tracker

Opened 10 years ago

Closed 10 years ago

#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:
Blocked by: Blocking:

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 (4)

comment:1 Changed 10 years ago by 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:2 Changed 10 years ago by jerone

With the closing tag on the <form/> it also works on IE8.

comment:3 in reply to:  1 Changed 10 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 10 years ago by dmethvin

Resolution: invalid
Status: newclosed

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.

Note: See TracTickets for help on using tickets.