25
Grexius
7y

Did anybody else know that putting comments in your HTML creates an EMPTY TEXT NODE IN THE DOM?
REAL helpful information when you have to GATHER EVERY ELEMENT WITH TEXT INSIDE OF IT!

WHY WOULD HTML EVEN BE LIKE THIS? IT'S A COMMENT! WHY DOES IT HAVE ANY EFFECT, even if it's minimal, ON THE DOM WHATSOEVER, THIS DOESN'T MAKE SENSE!

Comments
  • 4
    It does make sense, its part of the document!
  • 0
    Turns out that the issue that made me discover this comment problem was actually pretty bad and required a fix regardless.
    I still think it's dumb that the presence of a comment changes the DOM, but at least it helped me in some way.
  • 0
    Really ? I am confused
  • 1
    Document Object Model of a eXtensible Markup Language document. What do you think happens, comments are a valid dom node type.^^

    Show us what Happens if you don't have a newline between stuff and comment.

    <body><!-- comment -->text
    Because its not empty, it clearly is a newline. And those are simply characters and thus completely cool to put into a text node. Cus you have them as text there.
Add Comment