Closed Bug 431074 Opened 16 years ago Closed 14 years ago

<label> with <div> as child in source appears as sibling in DOM

Categories

(Core :: DOM: HTML Parser, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: johnhoogstrate, Unassigned)

References

()

Details

(Keywords: html5, testcase, Whiteboard: [fixed by the HTML5 parser])

Attachments

(2 files)

User-Agent:       Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9b5) Gecko/2008032619 Firefox/3.0b5
Build Identifier: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9b5) Gecko/2008032619 Firefox/3.0b5

Placing a div-element within a label-element in the HTML source causes appears as the next sibling in the DOM causing unexpected behavior in scripts.

The effect of this bug can also be observed in the DOM inspector.

A testcase is provided with this bug report. Both Opera and Safari do not suffer from this problem.

Reproducible: Always

Steps to Reproduce:
1.
2.
3.
Component: General → DOM
Product: Firefox → Core
QA Contact: general → general
Version: unspecified → Trunk
DIV is a block-level element, LABEL can only contain inline:
http://www.w3.org/TR/html401/interact/forms.html#edef-LABEL
(the terms "block" and "inline" in the HTML4 sense)

Don't confuse this with CSS 'display' values.
You can use SPAN as a child and style it with display:block if that
was your intention.

The current parsing is correct per HTML4.

HTML5 refers to WF2:
http://www.whatwg.org/specs/web-apps/current-work/#forms
which also has the same content model:
http://www.whatwg.org/specs/web-forms/current-work/#xhtml-module-def
and there is no mention of any change in this respect in:
http://www.w3.org/TR/html5-diff/

-> INVALID
Status: UNCONFIRMED → RESOLVED
Closed: 16 years ago
Resolution: --- → INVALID
I reopen this bug because moving elements to another position inside the DOM tree is an extremely unusual way of handling HTML that does not conform to the W3C recommendation and is not documented anywhere or recommended as a error correction mechanism.

Many other elements like for example <span> cannot contain block-level elements according to the recommendation. Firefox does not exhibit this behavior for other elements than <label> for which the same restrictions apply. 

All modern browsers that are considered to be more standard compliant are able to handle this specific don't exhibit similar behavior.
Status: RESOLVED → UNCONFIRMED
Resolution: INVALID → ---
After reading the (current draft) HTML5 parsing chapter more closely
I agree this is a bug according to HTML5:
http://www.whatwg.org/specs/web-apps/current-work/multipage/section-tree-construction.html

Comparing Opera, IE and Safari they seem to be closer to HTML5
than we are, although they all have bugs too.

(Regarding HTML4, it's anybody's guess what the correct tag soup
error recovery is since it's not really specified.  FWIW, it looks
like the aim of our current error recovery is to avoid violating
the content model for the open elements on the parse stack.)
Component: DOM → HTML: Parser
Keywords: testcase
OS: Mac OS X → All
QA Contact: general → parser
Hardware: Macintosh → All
Attached file Testcase #1
Indeed this behavior seems to occur in the HTML parser and not the DOM. Adding a <div> element to a <label> using JavaScript seems to work fine.
(In reply to comment #3)
> After reading the (current draft) HTML5 parsing chapter more closely
> I agree this is a bug according to HTML5:
> http://www.whatwg.org/specs/web-apps/current-work/multipage/section-tree-construction.html

In this case I'll confirm this report.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Keywords: html5
I believe this is fixed by bug 487949.
Depends on: html5-parsing
Status: NEW → RESOLVED
Closed: 16 years ago14 years ago
Resolution: --- → FIXED
Whiteboard: [fixed by the HTML5 parser]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: