3 Links and Comments
3 Links and Comments
Comments
T. Samih Mohamed
E.mail simoo111111@gmail.com
The <a> Element
The <a> element ("anchor") is used to create a clickable link
to another location. There are four varieties of links:
We will learn how the <a> element works and take a look at examples of each
of these link types, but first let's learn about element attributes.
Element Attributes
Attributes add information to an element and often control how an element is
displayed on the page. Here is the <a> element with two attributes defined:
attribute attribute
attribute value attribute value
Each element has its own set of attributes available. Usually these attributes are
optional, but in some cases they are mandatory.
Attribute names must be in lowercase and attribute values must be enclosed in quotes.
Using the <a> Element
Whatever text is placed between the <a> and </a> tags will display on the web
page and become a clickable link. This is often referred to as anchor text:
<body>
<p>If you're uncertain, just
<a href="http://www.google.com" target="_blank">look it up on Google</a>.
</p>
</body>
The web server will assume that this The target="_blank" attribute is
file is located in the same folder as usually omitted for links within our
the current page. If the linked page own site. We want the existing
were located somewhere else, we window to move to the new page.
would need to include a path to that Otherwise, we would clutter up the
location. We'll learn more about browser window with multiple tabs,
paths in an upcoming lesson. each containing a different page from
our site.
Internal links like these are how we build a navigation menu to allow our visitors to
move from page to page on our site.
Example: Bookmark Link
A bookmark link is a link to another location within the existing web page.
This special link is created using two separate <a> elements. The first one
establishes the link by using an href attribute of "#" (pound sign) followed by
the name of the destination anchor:
The second <a> element names the destination anchor by using the id
attribute. Since it does not include the href attribute, this <a> element does
not create a clickable link and will be invisible to the visitor.
The destination anchor does not have to come after the link anchor and can be located
anywhere on the page. Bookmark links like these are most commonly used to build a
clickable table of contents within a page.
Example: Email Link
To create a link that automatically starts a new email message, we use
mailto: in the href attribute instead of a web page address:
<body>
<p>If you like my site, please
<a href="mailto:me@domain.com">send me an email!</a>
</p>
</body>
When the link is clicked, the visitor's default email application is launched and a new
message created. The destination email address is required.
XHTML Comments
We can add personal comments throughout our web pages.
These will not appear on our live web pages. Some typical
reasons to add comments are:
To make notes to ourselves explaining the purpose of certain lines
of code.
To indicate to fellow team members where future changes or
improvements will go.
To inform future programmers about how the page works and of any
known pitfalls with modifying content.
Memory fades over time and it can be a time-consuming chore to "get back up to
speed" on a page written months or years ago. Comments can make things much
easier.
Comment Syntax
Comments begin with "<!--" Comments end with "-->"
The browser will consider everything between the <!-- and the --> as part of
the comment and will therefore disregard it. Comments can span multiple
lines, as line breaks and spaces make no difference.
WARNING: Be careful what you write! Although comments are not displayed on the
live web page, they are still in the web document and can be seen by any user who
knows how to view the original source code of a website.
Viewing Source
All web browsers have the ability to view the underlying code that creates a
web page. In Chrome, shown above, a user can see the code in a separate
window by right clicking directly on the web page and choosing "View page
source." Notice that it displays our comments and colors them green.