mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 02:07:34 +00:00

Getting the innerHTML property will recurse through the subtree inside the element and serialize it into a string as it goes. Setting it will parse the set value as an HTML fragment. It will then remove all current children of the element and replace them with all the children inside the parsed fragment. Setting element.innerHTML will currently force a complete rebuild of the document's layout tree. This is pretty neat! :^)
17 lines
470 B
HTML
17 lines
470 B
HTML
<!DOCTYPE>
|
|
<html>
|
|
<head>
|
|
</head>
|
|
<body>
|
|
<div id=clicky style="background-color: red; color: white; border: 1px solid black;">Click me</div>
|
|
<div id="foo">This has <b>some HTML</b> inside it!</div>
|
|
<script type="text/javascript">
|
|
function hax() {
|
|
var foo = document.getElementById("foo");
|
|
console.log("trying");
|
|
foo.innerHTML = 'But now the HTML has changed!';
|
|
}
|
|
document.getElementById("clicky").addEventListener("mousedown", hax);
|
|
</script>
|
|
</body>
|
|
</html>
|