Bug Tracker

Opened 12 years ago

Closed 12 years ago

#2383 closed bug (invalid)

appending HTML element such as $("<a>") doesn't work in IE

Reported by: tjdeater Owned by:
Priority: major Milestone: 1.2.4
Component: core Version: 1.2.3
Keywords: Cc:
Blocked by: Blocking:

Description

Test case, execute the following in IE and FF and compare the results:

alert($("<p>").append($("<a>")).html());

alert($("<p>").append($("<a></a>")).html());

First alert is blank in IE, shows <a></a> in FF.

Second alert shows <A></A> in IE and <a></a> in FF.

Is $("<a></a>") the preferred method? I've used $("<a>") successfully prior to jQuery 1.2, but 1.2.1, 1.2.2, and 1.2.3 all exhibit this behavior. $("<span>") exhibits the same behavior.

Change History (3)

comment:1 Changed 12 years ago by tjdeater

Disregard. I just checked the documentation and apparently I've been doing this incorrectly all along:

For example, to create a span use $("<span/>") or $("<span></span>") instead of without the closing slash/tag.

But it used to work! I swear!

comment:2 Changed 12 years ago by tjdeater

I am a little confused by this however:

alert($("<div>").append($("<span>")).html()); alerts blank in IE

alert($("<div>").append($("<p>")).html()); alerts <P></P> in IE

The docs say "When creating single elements use the closing tag or XHTML format." but I'm not sure what is meant by "single elements". Is a question of block vs inline elements as in the above example? But if that's the case, why does this work in IE without the XHTML format?

alert($("<div>").append($("<img>")).html()); alerts <IMG> in IE

comment:3 Changed 12 years ago by scott.gonzal

Resolution: invalid
Status: newclosed

Single element means one element (no children or content). The reason $("<p>") and $("<img>") work is because the HTML spec says that these elements do not need to be closed, so IE handles them fine without closing tags or the XHTML self-closing format.

Note: See TracTickets for help on using tickets.