Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE10 giving me error 1509, unmatched end tag

In IE10, I create the following web page, and get an unmatched tag error:

<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
    <p>
        <div>
            &nbsp;
        </div>
    </p>
</body>
</html>

I can find no problem with this code. I have narrowed it to having a div inside a paragraph as what is triggering the problem. IE10 reports:

HTML1509: Unmatched end tag.
test.php, line 12 character 2

and is pointing to the paragraph close token. An earlier me might have just ignored it. But I can't make myself do that any more.

I have searched this site for something similar, but have found only legitimate syntax errors; valid explanations for the error, in other words. I know IE is brain-dead, but even post-Bill MSFT can't be silly enough to let a bug like that one, through (can they?). So I am assuming it's me, until proven otherwise. Possibly some subtlety of HTML5 I haven't grokked yet...

like image 798
Phil - Computer Whisperer Avatar asked Dec 04 '22 10:12

Phil - Computer Whisperer


1 Answers

You can't have DIV (or any other block element) in a P unless you serve your markup as application/xhtml+xml. All pages served as text/html are parsed by HTML parser (in modern browsers, including IE10, it's HTML5 parser, regardless the doctype). In HTML, the content model of P element is 'phrasing content' (HTML5) or 'inline' (HTML4), and its end tag is optional in all versions of HTML. So the parser implicitly closes the P element before the opening tag of any block element. And in all browsers the DIV element will be not the child of P, but the sibling, and CSS selectors like p > div will never work for pages served as text/html.

like image 81
Ilya Streltsyn Avatar answered Dec 06 '22 23:12

Ilya Streltsyn