Skip to main content

Bug Tracker

Side navigation

#2383 closed bug (invalid)

Opened February 21, 2008 10:47PM UTC

Closed February 22, 2008 02:29AM UTC

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.

Attachments (0)
Change History (3)

Changed February 21, 2008 11:06PM UTC by tjdeater comment:1

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!

Changed February 21, 2008 11:13PM UTC by tjdeater comment:2

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

Changed February 22, 2008 02:29AM UTC by scott.gonzal comment:3

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.