Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /css/css-text/white-space/white-space-trim-dynamic.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>white-space-trim: dynamically setting the value triggers relayout</title>
<link rel="match" href="reference/white-space-trim-dynamic-ref.html">
<meta name="assert" content="Changing white-space-trim on an already-laid-out inline box relayouts the line, collapsing the adjacent white space.">
</head>
<body>
<p>Test passes if both lines below read "ab" / "cd" with no space between the letters.</p>
<div>a <span id="before">b</span></div>
<div><span id="after">c</span> d</div>
<script>
// Force an initial layout with the white space present ("a b" / "c d")...
document.body.offsetHeight;
// ...then change white-space-trim. This must trigger a relayout that collapses the
// now-discarded white space, otherwise the old (untrimmed) line boxes remain.
document.getElementById('before').style.whiteSpaceTrim = 'discard-before';
document.getElementById('after').style.whiteSpaceTrim = 'discard-after';
</script>
</body>
</html>