javascript - HTMLElements are not found by .getElementById() if commented out - is this normal behavior? -
I was trying to see how the .hasAttribute ()
method returned . I had the following code:
HTML:
My console is throwing this error: Unkit type error: property can not be read 'attribute' of zero
Interestingly, once I did without the comment HTML, myimg
was no longer nonsense, and .hasAttribute ('src');
Returns a Boolean with pleasure
Since I have tried: .getElementById
.getElementById ()
to work, e.g.
.getElementById ()
, Which simply says "If there is no element from the given ID, then this function returns
null
... is not in the elements The document is not discovered by getElementById. "
But there is definitely a part of the commented document!
I've been searching for it, but I did not answer my question.
Yes, this is normal as your question is ridiculous, it appreciates a real answer : Whatever you comment is inserted as a comment node in the DOM, and it is not considered as a markup. A comment is like nothing is a hidden form element : First is not a dom node, but annotation data. The second is a real dom node, and if you apply it to a CSS such as display: block
it looks like something else on the page.
And I asked this question funny, because it is one of the most basic rules of HTML markup HTML does stuff, if you turn it off, it does nothing and as far as anyone Also worried, does not even exist when you see the source.
Comments
Post a Comment