Comments in HTML CSS and JS

Source: Internet
Author: User
Tags html comment

One, HTML annotation method <!--HTML comment: START-to-content <!--HTML comment: END-to

The content that is contained between <!--and--is ignored by the browser and is not displayed in the user's browsing final interface.

The part of the comment is ignored while the browser is executing, but you can still see it when you view the source code in the browser

Second, the CSS annotation method <style type= "TEXT/CSS" >/* CSS comments */</style>

This method annotation is also used in a separate CSS style sheet file

three, JS annotation method <script type= "Text/javascript" >//js single-line annotation mode

/*

This is JavaScript.

Multi-line Comment mode

*/</script>

Write in JS

<!--

-

The roles and causes are as follows:

JavaScript recognizes the beginning of the HTML comment "<!--", and JavaScript ends it as a single-line comment, as with "//". But JavaScript does not recognize the result part of the HTML comment "--".

Therefore, if the first line starts with "<!--" and the last line ends with "//-->", JavaScript ignores both lines without ignoring the parts between the two rows. And if in JavaScript, the first line starts with "<!--",

The last line ends with "--" and the program is included in a full HTML comment that is ignored by browsers that do not support JavaScript and cannot be displayed.

In this way, you can hide code for browsers that don't understand JavaScript, and browsers that understand JavaScript don't have to be hidden.

Ps:

Where HTML comments are added to CSS (style) or JavaScript (script) code <!––> is to prevent the lower version of the browser from not supporting style and script code, and displayed in the page.

A browser that supports style will ignore the <!– tag and use the style sheet normally.

Comments in HTML CSS and JS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.