A comment is a way for you as the web page developer to control what lines of code are to be ignored by the web browser.
There are three main reasons you may want your code to be ignored.
All combinations of text placed within the comment tags will be ignored by the web browser, this includes any HTML tags, scripting language(s), etc.
Now when we are ready to display that element, we can simply remove the comment tags and our browser will readily display the element.
With this example we are jumping far ahead, just be sure you understand when to use comments and where to look for them. They are a very useful tool for any large project.
There are three main reasons you may want your code to be ignored.
- Writing notes or reminders to yourself inside your actual HTML documents.
- Scripting languages such as Javascript require some commenting.
- Temporarily commenting out elements especially if the element has been left unfinished.
HTML Code:
<!--Note to self: This is my banner image! Don't forget -->
<img src="http://www.tizag.com/pics/tizagSugar.jpg" height="100" width="200" />
Comment to self:
As you can see comment syntax may be a little complicated, there is an opening and a closing much like tags.- <!-- Opening Comment
- -- > Closing Comment
All combinations of text placed within the comment tags will be ignored by the web browser, this includes any HTML tags, scripting language(s), etc.
HTML - <!-- Commenting Existing Code -->
As a web developer often times you may have many works in progress, or elements that aren't quite finished. In this case you may comment out an element until it is 100% ready for the site. Below we have commented out an input form element since we are not quite ready to receive input from our users.HTML Code:
<!-- <input type="text" size="12" /> -- Input Field -->
HTML Code:
<input type="text" size="12" />
Input Field:
Comment out elements and bits of code that you may want to recall and use at a later date. Nothing is more frustrating than deleting bits of code only to turn around and recode them.HTML - <!-- Commenting Scripts -->
Scripting languages such as Javascript and VBScript must be commented out as well. You will learn that once they are placed within the <script> tags, only then does the browser correctly execute the scripts.HTML Code:
<script>
<!--
document.write("Hello World!")
//-->
</script>
0 comments
একটি মন্তব্য পোস্ট করুন