Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

  • This WPT test may be referenced by the following Test IDs:
<!DOCTYPE html>
<html>
<head>
<title>HTML Templates: Template is a foster parent element</title>
<meta name="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru">
<meta name="assert" content="The last template element with either no table element is below it, or a table element immediately below it, in the stack of open elements is the foster parent element (NOT the template's parent!)">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/html/resources/common.js"></script>
</head>
<body>
<div id="log"></div>
<script type="text/javascript">
test(function () {
var doc = newHTMLDocument();
doc.body.innerHTML = '' +
'<div id="tmplParent">' +
'<template id="tmpl1">' +
'<table id="tbl">' +
'<tr><td>Cell 1</td></tr>' +
// Misplaced <div>. It should be foster parented
'<div id="orphanDiv">Orphan div content</div>' +
'<tr><td>Cell 2</td></tr>' +
'</table>' +
'</template>' +
'</div>';
var template = doc.querySelector('#tmpl1');
var div = template.content.querySelector('#orphanDiv');
assert_equals(div.parentNode, template.content, 'Wrong foster parent element');
}, 'Template is a foster parent element. Test <table> immediately below <template>');
test(function () {
var doc = newHTMLDocument();
doc.body.innerHTML = '' +
'<div id="tmplParent">' +
'<template id="tmpl1">' +
'<tr><td>Cell 1</td></tr>' +
// Misplaced <div>. It should be foster parented
'<div id="orphanDiv">Orphan div content</div>' +
'<tr><td>Cell 2</td></tr>' +
'</template>' +
'</div>';
var template = doc.querySelector('#tmpl1');
var div = template.content.querySelector('#orphanDiv');
assert_equals(div.parentNode, template.content, 'Wrong foster parent element');
}, 'Template is a foster parent element. Test <template> element without <table>');
</script>
</body>
</html>