id and class attributes

The id attribute is used to identify elements and mark up specific functional areas of a
website, and the class attribute is used to classify one or more elements. These important
attributes help you target elements when it comes to styling or scripting. I refer to both of
these attributes throughout the book, but for now all you need to know is that a specific
id attribute value can be used just once per page, whereas a class attribute value can be
used multiple times (the attributes themselves can be used multiple times per page). For

example, say you begin a document with this:
<body id="homepage">

You would then not be able to use an id attribute value of homepage anywhere else on the
same page. However, if you do this:
<body class="homepage">

then you are free to use the class attribute value of homepage as many times as you like
throughout the same page, but bear in mind that it still applies the same CSS, no matter
what tag you apply it to.

<div id="rightColumn">
<strong class="redText">
<p class="big">

Divs and spans

Divs and spans are two tags that, when used well, can help give your page a logical structure
and some extra hooks to apply any CSS or DOM scripting that you might need later. When
used badly, they can litter your document unnecessarily and make your markup, styling, and
scripting needlessly complicated.


<div id="header">
...
</div>
<div id="mainContent">
...
</div>
<div id="secondaryContent">
...
</div>
<div id="footer">
...
</div>

A span is used for marking out sections within a block element and sometimes inside
another inline element. It is an inline element, just the same as <em>, <strong>, or <a>,
except without any semantic meaning—it is simply a generic container. It can itself contain
further inline elements, including more spans. For example, say you wish to color the first
two words of a paragraph red, keeping the rest of the paragraph black. You can use a
<span> for this:
<p><span class="leadingWords">The first</span> two words of this å
paragraph can now be styled differently.</p>
A span cannot contain a block element—that is, you cannot place a <div> within a <span>
and expect it to work the way you want.

CSS and Canvas HTML5

As with most HTML elements, CSS can be applied to the canvas element itself to add borders, padding,
margins, etc. Additionally, some CSS values are inherited by the contents of the canvas; fonts are a good
example, as fonts drawn into a canvas default to the settings of the canvas element itself.
Furthermore, properties set on the context used in canvas operations follow the syntax you may
already be familiar with from CSS. Colors and fonts, for example, use the same notation on the context
that they use throughout any HTML or CSS document.
Browser Support for HTML5 Canvas
With the arrival of Internet Explorer 9, all browser vendors now provide support for HTML5 Canvas, and
it is already in the hands of a majority of users. This is a major milestone in web development, allowing
2D drawing to thrive on the modern Web.
In spite of the dwindling market share of previous versions of Internet Explorer, it is still a good idea
to first test whether HTML5 Canvas is supported before you use the APIs. The section “Checking for
Browser Support” later in this chapter will show you how you can programmatically check for browser
support.

Overview of HTML5 Canvas

When you use a canvas element in your web page, it creates a rectangular area on the page. By default,
this rectangular area is 300 pixels wide and 150 pixels high, but you can specify the exact size and set
other attributes for your canvas element.  A Basic Canvas Element
<canvas></canvas>
Once you have added a canvas element to your page, you can use JavaScript to manipulate it any
way you want. You can add graphics, lines, and text to it; you can draw on it; and you can even add
advanced animations to it.
The Canvas API supports the same two-dimensional drawing operations that most modern
operating systems and frameworks support. If you have ever programmed two-dimensional graphics in
recent years, you will probably feel right at home with the Canvas API because it is designed to be similar
to existing systems. If you haven’t, you’re about to discover how much more powerful a rendering
system can be than the previous images and CSS tricks developers have used for years to create web
graphics.
To programmatically use a canvas, you have to first get its context. You can then perform actions on
the context and finally apply those actions to the context. You can think of making canvas modifications
as similar to database transactions: you start a transaction, perform certain actions, and then commit
the transaction.

Using the Selectors API HTML5

getElementById() -Returns the element with the specified id attribute value
<div id="foo">
getElementById("foo");

getElementsByName() -Returns all elements whose name
attribute has the specified value
<input type="text" name="foo">
getElementsByName("foo");

getElementsByTagName() Return all elements whose tag name
matches the specified value
<input type="text">
getElementsByTagName("input");

With the new Selectors API, there are now more precise ways to specify which elements you would
like to retrieve without resorting to looping and iterating through a document using standard DOM. The
Selectors API exposes the same selector rules present in CSS as a means to find one or more elements in
the page. For example, CSS already has handy rules for selecting elements based on their nesting,
sibling, and child patterns.

CSS File for the HTML5 Page

body {
background-color:#CCCCCC;
font-family:Geneva,Arial,Helvetica,sans-serif;
margin: 0px auto;
max-width:900px;
border:solid;
border-color:#FFFFFF;
}
header {
background-color: #F47D31;
display:block;
color:#FFFFFF;
text-align:center;
13
}
header h2 {
margin: 0px;
}
h1 {
font-size: 72px;
margin: 0px;
}
h2 {
font-size: 24px;
margin: 0px;
text-align:center;
color: #F47D31;
}
h3 {
font-size: 18px;
margin: 0px;
text-align:center;
color: #F47D31;
}
h4 {
color: #F47D31;
background-color: #fff;
-webkit-box-shadow: 2px 2px 20px #888;
-webkit-transform: rotate(-45deg);
-moz-box-shadow: 2px 2px 20px #888;
-moz-transform: rotate(-45deg);
position: absolute;
padding: 0px 150px;
top: 50px;
left: -120px;
text-align:center;
}
One last thing to keep in mind is that browsers may seem to render things as if they actually
understand these new elements. The truth is, however, that these elements could have been renamed
foo and bar and then styled, and they would have been rendered the same way (but of course, they
would not have any benefits in search engine optimization). The one exception to this is Internet
Explorer, which requires that elements be part of the DOM. So, if you want to see these elements in IE,
you must programmatically insert them into the DOM and display them as block elements.

Submitting to directories

By now you’ve figured out that directories work differently from search engines. You must complete
the submission process to have your site included in most directories. But even when you’re submitting
information about your site, there’s an art to doing it.
How you list your site can mean the difference between the site being included in the directory or
not. Before you even begin to create your listing, it’s usually a good idea to navigate through the
directory that you’re submitting to. Look at other listings and make note of what works in them.
Keywords are of little importance when you’re creating your directory listing. Instead, what will make
the difference is the content on your web site. So if you’re faced with listing in a directory that’s strict
about reviewing sites before they are listed, make sure you have fresh content on your site. And it’s
also a good practice to keep that content fresh by updating it regularly.
Links can also be important when your site is being reviewed for inclusion in a directory, so be sure
you keep your links updated. Broken links can be detrimental to your site, and links that lead to
unrelated pages won’t reflect well either.
Other elements of your listing that editors evaluate for include:
1. Appropriate categorization
2. Accurate titles and descriptions
3.Title and descriptions relevant to the subject of the web site
4.Domain names that match site titles
5.Secure ordering capabilities on e-commerce sites
6.Contact information that’s easily accessible
7.Links to privacy policies, return policies, and product or service guarantees
8.Working and appropriate links to other sites and resources
9.Images that display properly in the most common browser formats
10.JavaScript that’s free of errors

Yahoo! Search Marketing

Another type of search engine is the directory search engine. Directories don’t display search results
based on keywords; instead they display results by category and subcategory. Web sites are usually
categorized by the site, not by pages on the site. What this means is that your overall listing in directory
search results will depend largely on either paid placement or on correctly categorizing your site
as tightly as possible.
Yahoo! Search Marketing is a PPC program that’s similar to AdWords, but there’s one big difference.
Yahoo! is a very commercial search engine, which means that many of the search results are
paid placement ads or are web sites that have been added by the web-site owner. Editors usually
review and approve submitted listings before they are shown in search results.
Yahoo! is also a portal that contains many different services, such as instant messaging, e-mail, maps,
and much more (Google is structured in a similar manner). Being a portal means that Yahoo! has
many loyal users who are likely to see your ads once you begin a PPC campaign with Yahoo! Search
Marketing.
When you sign up with Yahoo! Search Marketing, you have two options for the type of account you’d
like to have. These options are different from Google, because you can have a free PPC plan that you
use, create, and maintain on your own, or you can choose to have a Yahoo! specialist help you create
your campaign. If you decide to use a Yahoo! specialist, there’s a one-time $199 set-up fee.
As with Google, there’s no reason you should pay to begin your PPC advertising with Yahoo! Search
Marketing.

Google AdWords

Google AdWords is the PPC company you’ve probably heard the most about. AdWords is one of
the top search engine marketing programs, and Google is one of the biggest providers of search,
and many other services as well.
Being biggest doesn’t always mean being the best, though. When you’re evaluating the PPC companies
you may use, be sure to check not only the traffic rate, but also the conversion rate if possible.
It’s great if your ads receive lots of impressions, but if those impressions don’t turn to clicks, you’ll
find your PPC campaign is not at all effective.
Google AdWords. You may have heard the name so often that you think there’s nothing else — and
certainly it’s one of the most diverse PPC companies out there. It not only offers search engine marketing,
but also includes marketing by radio and even a telephone service that potential customers
can use to call you. Google will soon begin offering purchase of TV, newspaper, and embedded video
advertising. Even the radio and phone models of AdWords are charged on a bid-per-keyword basis.
Additionally, AdWords is linked to Google’s AdSense program, which is an advertisement publishing
program in which web-site owners place ads on their web sites; when users click through those ads
and make purchases, the web-site owner gets paid a small amount. Many web-site owners use this
service to help offset the cost of having a site.
AdWords ads are shown when someone searches on Google, AOL Search, Ask.com, and Netscape.
This gives Google AdWords one of the largest markets for keyword advertisements. However, a
larger market doesn’t guarantee a higher quality lead, so when using AdWords, it’s essential that
you pay attention to the details that help your ads place when they’re most effective.

Improving Click-Through Rates

Some of the efforts you take to reduce the cost of your PPC campaigns can also lead to improved
click-through rates. It’s essential that you work toward increasing these rates. Even though more
clicks drive up the cost of your PPC campaign, they also lead to more sales or conversions.
Aside from the efforts that you’ve already seen (like dayparting and better targeting) you can also
improve your click-through rates by improving the ad copy in your PPC campaigns.

Include special offers or incentives in ad text. If you have coupons to offer, discounts
available, or even free gifts with purchase or other special offers and incentives, be sure
those are included in your PPC ad text. People are drawn to specials, and advertising them
should draw more people to your site.
Consider including price in ads for products and services. Many people shy away from
advertising their prices, but those prices (especially if they’re real bargains) can entice customers.
If you have great prices, tell the world. Just make sure you check out the competition
before you decide you have the best prices on the Internet.