Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Brendan WhitingFront End Web Development Techdegree Graduate 84,733 Points
Browsers read HTML comments?
I thought comments were just comments that got ignored. But this lecture: https://teamtreehouse.com/library/cross-browser-testing is saying that browsers actually read the contents of comments and interpret the programmatically. I don’t really follow how this works. Why wouldn’t a browser just ignore the comments and look at the link regardless?
<!—[if gte IE 9]> <link href=“…”> <![endif]—>
That is an example of a Conditional comment. It is a system created by Microsoft for Internet Explorer. Specifically it was supported by Internet Explorer from version 5 to 9
The fact that it looks like a standard comment is intentional, that was done so that other browser would not be affected by the code added specifically to deal with the different IE versions.
So to sum up, it is technically speaking a normal comment, and it will be ignored by most browsers. But old version of IE will specifically look for them and treat them like code.
Hey Brendan! Im pretty confident that they dont get read by the browser. This is what i have been told all along atleast, ofcouse the intepreter has to look at the text in order to evaluate that its a comment, but i think thats about it.
However when you make a comment in html it should look like this:
<!--This is a comment. Comments are not displayed in the browser-->
Notice that you need 2 "-", but you only put 1. That might of been the issue. Hope this helps!