I've noticed that inside HTML textarea element I can set almost any default value without escaping and access it from JavaScript through that element node's value property like below:
HTML:
<textarea id="txt">
<h1>A h1 heading</h2>
<!-- this is comment -->
<textarea>This is a textarea</textarea>
</textarea>
JS:
console.log(txt.value)
JS Output:
<h1>A h1 heading</h2>
<!-- this is comment -->
<textarea>This is a textarea</textarea>
To print the nested textarea tag I only needed to escape that <. If escape all the angle brackets then it also works. But that is too much work.
My question is it the standard behavior? I've found no articles or docs saying about. I looked into spec. But it seemed too complex. Is it safe to build app assuming it will work like this on all browsers? Can you please give reference to part of the spec that explains this?