Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

whitespace text nodes in the Chrome DOM

The below HTML:

    <html>
      <body>
          <label>field a</label>
          <input  name="foo1" value=""/><br/>
          <label>field b</label><input name="foo2" value="" /><br/>
      </body>
    </html>

… renders the input of field a slightly off to the right due to the whitespace between the label and the first input element. However, looking at the DOM in Chrome I see this:

enter image description here

I.e. there is no representation of the text node in the DOM. Since the browser renders it with the extra space I think what's happenning is that a whitespace is indeed present in the DOM but the DOM viewer for some reason does not display it. If I understand correctly Firefox DevTools do in fact display whitespace text nodes (see this blog post). Is there anything similar for Chrome?

like image 519
Marcus Junius Brutus Avatar asked Sep 19 '17 18:09

Marcus Junius Brutus


People also ask

What is whitespace text nodes?

HTML adds "white space text node" after some elements ( all inline elements), because it considers the white space between these elements part of them and it preserves them. So you can remove white space in html source or with javascript: from the inspector see which element has nextSibling empty text node.

What is whitespace in HTML?

Whitespace refers to characters which are used to provide horizontal or vertical space between other characters. Whitespace is often used to separate tokens in HTML, CSS, JavaScript, and other computer languages.

How do I make white space in HTML?

To insert blank spaces in text in HTML, type &nbsp; for each space to add. For example, to create five blank spaces between two words, type the &nbsp; entity five times between the words. You do not need to type any spaces between the entities.


1 Answers

I don't think there is a way to display them in the DOM view.

However, I've noticed they are somewhat detectable in the Accessibility Tree:

enter image description here

like image 127
Eyal Roth Avatar answered Nov 15 '22 06:11

Eyal Roth