Bug Tracker

Modify

Ticket #6819 (closed bug: duplicate)

Opened 4 years ago

Last modified 4 years ago

Creating DOM elements fails in IE when no closing tag

Reported by: adamlogic Owned by:
Priority: Milestone: 1.4.3
Component: manipulation Version: 1.4.2
Keywords: ie Cc:
Blocking: Blocked by:

Description

In IE, creating DOM elements fails if there is no closing tag. This only happens for certain elements, and it only happens if attributes or child elements are included.

Passes:

$('<form>').length == 1
$('<form id="foo" />').length == 1
$('<form id="foo"></form>').length == 1
$('<div id="foo">').length == 1  // works for some elements, not others

Fails:

$('<form id="foo">').length
$('<span id="foo">').length

I believe the problem is in the following lines of manipulation.js:

    var tag = (rtagName.exec( elem ) || ["", ""])[1].toLowerCase(),
      wrap = wrapMap[ tag ] || wrapMap._default,
      depth = wrap[0],
      div = context.createElement("div");

    // Go to html and back, then peel off extra wrappers
    div.innerHTML = wrap[1] + elem + wrap[2];

In the case of a form (or many other elements), here is what happens:

  div.innerHTML = 'div<div><form id="foo"></div>'

IE will tack the closing form tag after the closing div, like this:

  'div<div><form id="foo"></div></form>'

Then the following code will end up with the form instead of the containing div:

    while ( depth-- ) {
      div = div.lastChild;
    }

I'm not sure how to fix this, but I did write a failing spec. It's up on Github:  http://github.com/adamlogic/jquery/commit/5bf852d6ea6d5151e0107406dd3f7b6964dcd245

Change History

comment:1 Changed 4 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to duplicate

Dup of #6815

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.