Skip to main content

Bug Tracker

Side navigation

#11589 closed bug (cantfix)

Opened April 13, 2012 02:22PM UTC

Closed April 13, 2012 03:04PM UTC

Last modified April 13, 2012 09:22PM UTC

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.

Attachments (0)
Change History (2)

Changed April 13, 2012 03:04PM UTC by dmethvin comment:1

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.

Changed April 13, 2012 09:22PM UTC by Jay32 comment:2

Alright, thanks for looking into it.