Bug Tracker

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#11589 closed bug (cantfix)

Putting Html In A Div Closed Within Its Opening Tag, Causes Content Below That Div To Disappear

Reported by: Jay32 Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:

Description

http://jsfiddle.net/E3jVv/4/

Click on the text 'Click me'.

Apparently, it makes a difference whether the first div is closed like this:

<div id="first" />

Or like this:

<div id="first" ></div>

Using the first div, closed within its opening tag, causes Jquery to delete everything below that div when appending html to it.

Using the second div, closed with an explicit closing tag, it works as expected. The first div has some html set, and all other elements are left undisturbed.

Change History (2)

comment:1 Changed 8 years ago by dmethvin

Resolution: cantfix
Status: newclosed

Occurs regardless of jQuery or bare DOM: http://jsfiddle.net/E3jVv/6/

Imma point out that technically a self-closed div element is not valid markup because only elements that *cannot* have content can be self-closed. Your div can have content (in fact you're trying to add it) but it just doesn't happen to have content when the document is parsed.

The start and end tags of certain normal elements can be omitted, as described later. Those that cannot be omitted must not be omitted. Void elements only have a start tag; end tags must not be specified for void elements ... if the element is one of the void elements, or if the element is a foreign element, then there may be a single U+002F SOLIDUS character (/) ... http://www.w3.org/TR/html5/syntax.html#void-elements

It seems pretty strange to me, I agree, but technically you cannot self-close a div tag. We allow $("<div/>") but that actually creates a div element inside jQuery. Your case has the element in the markup so jQuery isn't involved in the creation of the tree at all.

comment:2 Changed 8 years ago by Jay32

Alright, thanks for looking into it.

Note: See TracTickets for help on using tickets.