Multiple text nodes in one element?

Can someone look at the following screenshot for me and explain the following:

Image showing weird behavior

  • What's happening?
  • How can I programmatically define it?
  • How can I programmatically fix / get rid of it?

I believe what happens when I have several text nodes in one element pre... I feel like I read on MDN many years ago that this is possible, but I have never seen anything like it before Now.

jQuery does not show anything unusual in this with text()or html()(I try both in the console and in the screenshot) ... it just shows the contents of all text nodes combined into one node.

It is not shown that when trying to manually fix this in the console by doing:

$('pre').text($('pre').text())

Instead of replacing all text nodes with a single text node with the contents of all 3 combined into one , it replaces the contents of the first text with node contents of all 3.

All this really confuses me, and I can not find any documentation about this, so I would really appreciate if someone could answer my questions above.

Oh, because I know that someone will ask how I did this, the answer is I'm not quite sure what I did. This has something to do with the circular loop between the html and js of my meteor project, I think:

In my html, I have this:

<pre class="editable" contentEditable="true">{{text}}</pre>

And in my javascript I have this:

"input pre": function (event) {
    var newText = $(event.target).text();
    Ideas.update(this._id, {$set: {text: newText}});
}

, text pre. , pre text . - - , ( .)

+4
1
  • ?

pre .

  1. ?

$('pre').contents() , . , , 1, . , , - . . jQuery.

  1. / ?

$('pre')[0].normalize() . . MDN.

+3

All Articles