Why does the newline character disappear after the preliminary tag?

Why doesn't the new line immediately after the <pre> tag appear in the DOM?

<html>
<body>

<div id="mydiv">
hello
div
world
</div>

<pre id="mypre">
hello
pre
world
</pre>

<script>
alert("div content: "+document.getElementById("mydiv").innerHTML)
alert("pre content: "+document.getElementById("mypre").innerHTML)
</script>

</body>
</html>

Shows that unlike line break after div tag, line break after pre-tag doesn't seem to be in dom. Also, innerHTML of the whole body does not show line breaks after the preliminary tag.

Is there any way to find out in JS if the source HTML document contains a line break after <pre> or not?

+4
source share
2 answers

Because what the specification says :

. HTML , pre, .

, , -, :

<pre id="mypre">

hello
pre
world
</pre>

: doctype, , , . ( , ).

+7

<pre>:

HTML , pre, .

, , :

<pre>Some text
some more
and more
</pre>

. :

<pre>
Some text
some more
and more
</pre>

, <pre> , .

, :

<pre id="mypre">

hello
pre
world
</pre>
+3

Source: https://habr.com/ru/post/1542757/


All Articles