Different types of SEO

This guide covers all major aspects of SEO, including:

• content SEO
• analytical SEO
• performance SEO
• Technical/HTML SEO
• Image SEO
• Off-site SEO

Where possible I will demonstrate techniques (or refer to other articles) with verifiable SEO
examples that you can look at on Google.

Content SEO

Content SEO refers to the techniques you can use to help content appear higher in the SERPs
(Search Engine Results Pages).
How to implement content SEO: Content SEO requires you to know which SEO keywords and
phrases you want to target. This in turn means you need to do some SEO keyword research before
sitting down to write.

The following articles tell you everything you need to know about content SEO:

• Anatomy of a blog post: How to get more traffic and s ocial engagement from your content
• Killer SEO tip: How to make the long tail pay

What's new in content SEO: Google's Panda and Penguin algorithm updates hit a lot of sites. Not
all of the updates affected content SEO - Penguin focused on spammy backlinks, for example.
However, almost all of Google's updates are designed to improve the quality of the content returned
by their search. Quality! That's the new buzzword. Good content SEO starts with high quality
content that is useful, engaging, valuable or entertaining.

Analytical SEO


Analytical SEO makes use of traffic analysis through an analytics service like Google analytics. By
analyzing the sources, demographics, browsing patterns and conversions of organic search traffic, it
is possible to improve your SEO strategy.

Small business SEO ROI calculation

For the purposes of the ROI (Return on Investment) calculation for small business SEO, we'll make
a few assumptions about the amount of traffic clicking through from Google (feel free to modify
these if you think they are different).

In both cases, we're looking at the traffic generated by results appearing on the first page of Google
that's the whole point of proper SEO after all.
To make the maths easy, let's assume that Google generates 100 000 impressions for your keywords
each month.

We'll also say that the ADV is $5 and that the conversion rate is 2%.
Top of 1st page results:
Monthly value of SEO = 100 000 x (20% click through) x $5 x 0.02 = $2000
Bottom of 1st page results:
Monthly value of SEO = 100 000 x (3% click through) x $5 x 0.02 = $300
The difference between ranking right at the top of the first page in organic search results, and at the
bottom of the first page is considerable. So the margins for error in SEO are very thin - second page
results may generate no traffic at all (depending on the popularity of the keywords).

Weekly SEO top 5

This SEO list for bloggers and small business will show you five things you should do at least once
a week in order to ensure that your blog or website is driving as much Web traffic as possible.
In many cases, the SEO or search optimization related tasks mentioned in this list should be
performed more than once a week.

1. Create content
Add content to your site at least once a week. If you rely on revenue from the Internet then it is
definitely worthwhile creating content on a more regular basis, as a high authority, highly ranked
niche website can bring great ROI (Return on Investment) online.
New content must be original and relevant to your blog or business niche. In addition, you might
consider doing some SEO keyword research to further enhance the rankings of your content in
search.

2. Monitor analytics
Analytical data, provided by a service like Google analytics, can tell you a great deal about how a
blog or website performs. In particular, it is important to pay close attention to the following
aspects:
• Overall traffic volumes: This metric can provide strong evidence for how well or poorly
various marketing and SEO efforts are paying off.
• Traffic originating from organic search: This provides insight into how well your blog or
website ranks in the SERPs( Search Engine Results Pages).
• Top content: This can tell you which posts bring the most traffic and allows you to tailor
advertising or marketing on these pages, or work to help other pages move up in the
rankings.
• Conversions: If you have set goals, analytics can provide data about how well your blog or
site is converting traffic to meet predefined objectives, such as newsletter signups or product
purchases.
• Bounce Rate: A high bounce rate may indicate poor or confusing web design, or poor
quality content. A low bounce rate is a good indication that your blog or site is engaging
readers well.
To learn more about analytics and how to use analytical data, I recommend reading the following
articles:
• Five awesome tips to extract valuable SEO secrets from Google analytics data
28
• How to double your search traffic using SEO, Webmaster t ools and Google analytics
• Five ways to make more money using analytics

SEO and Internet marketing diversity

So here it is, based on the current state of search, SEO and social, we can make some pretty
powerful deductions about how to move forward with the best SEO and Internet marketing strategy
possible.
The keywords for small business SEO and marketing in 2012 are diversity, authority, and
engagement.
Content diversity
Content needs to be diversified to cater for different needs now that direct product sale conversions
are likely going to diminish with Google's product search taking the majority share of the pie.
Community discussions, reviews, human interest articles are good ways to get around Google
product search and still offer value to readers, with the potential to convert.
SEO and Internet marketing diversity
Don't put all your faith in SEO. It's not clear what effects knowledge graph and product search will
have. Combine that with the current algorithmic fluxes and, while SEO is hugely important, you
should agree that having all your eggs in the proverbial SEO basket is probably not prudent.

Promote your website in the right ways

While most of the links to your site will be gained gradually, as people discover your content through
search or other ways and link to it, Google understands that you'd like to let others know about the
hard work you've put into your content. Effectively promoting your new content will lead to faster
discovery by those who are interested in the same subject. As with most points covered in this
document, taking these recommendations to an extreme could actually harm the reputation of your
site.
Good practices for promoting your website
Blog about new content or services - A blog post on your own site letting your visitor base
know that you added something new is a great way to get the word out about new content or
services. Other webmasters who follow your site or RSS feed could pick the story up as well.
Don't forget about offline promotion - Putting effort into the offline promotion of your
company or site can also be rewarding. For example, if you have a business site, make sure
its URL is listed on your business cards, letterhead, posters, etc. You could also send out
recurring newsletters to clients through the mail letting them know about new content on the
company's website.
Know about social media sites - Sites built around user interaction and sharing have made
it easier to match interested groups of people up with relevant content.
Avoid:
attempting to promote each new, small piece of content you create; go for big,
interesting items
• involving your site in schemes where your content is artificially promoted to the
top of these services

FILE NAMES FOR SEO

This is another are in which opinions are varied as to the effect of file
names on search engine ranking. But it’s good protocol to name your
files – webpages, mp3s, images, videos etc with useful, relevant
names, and since it definitely won’t hurt your rankings, I say ‘why
not?’. Without being spammy, you can choose wisely when naming
your files to make them relevant. If you have MP3s, don’t just name
them “track one” or something generic like that. Include the name of
your band, genre and track title for example, and remember to use
hyphens to separate your words
eg. “Blue-snake-rock-girls-are-cool.mp3”

Search engines like content that is updated regularly. If your site gets
stale, your ranking will drop because it becomes less relevant. Not
every kind of site lends itself well to updated content which is where a
blog can come in handy. A blog, by its nature can be any kind of
content and is frequently updated. If you are a band you can utilize a
blog even when you don’t have an album out because you can let your
fans know about what you are up to. Are you in the studio recording?
Post pics of your sessions or let them know what songs you are
working on. Share rough cuts of tracks – ask for feedback. Give your
fans the feeling they are getting some personal insight into your life as
an artist. This kind of regularly updated content not only helps develop
your relationship with your fans, keeping them engaged and coming
back to your site frequently, but it also looks good to the search
engines.
Also keep in mind that the more pages your site has, the better it
looks to search engines. So it’s important to keep adding pages on a

Know Your Network For Seo

Imagine going to battle without an understanding of the terrain, roads, buildings,
weather, or even your own fighting force’s tactics and capabilities. This is the situation
faced by many information security professionals when they initially attempt to monitor
their network environment. Knowing your network is akin to understanding your
military capabilities, strengths, and weaknesses when preparing for an enemy attack.
In information security, the enemy will change tactics continually, but you have a
“home field advantage” because the battleground is your network. History proves that
blindly charging into or defending the unknown will almost certainly end in defeat.
One of the best ways to express this concept comes from Richard Bejtlich, information
security professional and author of The Tao of Network Security Monitoring. In a January
2007 post on his blog,* Bejtlich describes the “Self-Defeating Network” as having
the following characteristics:

• Unknown
• Unmonitored
• Uncontrolled
• Unmanned
• Trusted

Although you may not have control of or influence over these characteristics, you must
make every effort to Know Your Network! Doing so will help you succeed in most of
your security-related endeavors. In this chapter, we will explore two primary methods
of learning about a network: network taxonomy and network telemetry.

How To Increase Traffic to Your Website

• Review sites are the most cost-effective form of social marketing for small, local businesses.
• Make sure your listings on review sites include plenty of relevant keywords so that people can find
you in search results.
• Respond to negative reviews, but always remain calm and try to resolve the issue.
• Unlock your business page at Yelp.
• Post stickers and badges on your websites and physical locations to encourage more reviews.

Considerations for Multi-Lingual Sites

Creating SEO-optimized content for a multi-lingual web site presents a whole new challenge for
SEO. Needing a multi-lingual site is a good problem to have. It usually means that you have customers
in multiple countries. However, it also means you have to double or triple your SEO efforts.
The good news is that optimizing your foreign-language web site is very much the same as optimizing
your English one. You just do it in a different language. Here are some guidelines that should
serve as reminders of what you should plan to do during the SEO process:
Translate keywords into the new language. In some cases, you won’t be able to translate
your keywords into a matching word in another language. In that case, you’ll need
to choose new keywords.

Translate existing web content. Again, translations can sometimes be squirrelly. Unless
you’re an expert in the language to which you’re translating, hire someone to do it for you.
A bad translation could cost you more in lost traffic than the services of a good translator.
Apply all of the same SEO rules to your foreign content that you’ve learned for your
English content. Just because the language is different doesn’t mean that the search
engine or the search engine crawler is any different.

Include the proper links both to and from your English site to your foreign-language
site, but also include the appropriate links to English on the foreign-language site.
Make language options clearly available on your web site. If these options are not clearly
marked, your foreign visitors could miss them, and then you’ll lose visitors before they’re
fully engaged in your site.

SEO is really no different in any other language than it is in English. The biggest concern when
translating your site to another language is the actual translation. The SEO efforts are essentially
the same, but getting the language wrong could cost you just as much as not having a foreignlanguage
site at all.

Seoo Traffic Sources

On this page, you can see a summary of your inbound traffic. This includes direct traffic,
search engine traffic, and referring sites traffic. The top part of the page shows this type
of information.

The bottom part of the page is divided into two tables. The table on the lower left shows
a summary of your main sources of traffic. The table on the lower right shows the
pertinent keywords bringing the traffic.

The submenu options under the Traffic Sources main menu item include pages that
show segregated views of traffic. If you are using Google AdWords, you will see the
options relevant to AdWords paid ad traffic. Other SEM networks can have tagging
included in the

OFF-PAGE OPTIMIZATION

This refers to ways to improve your site’s ranking that involve 3rd party
sites, not just your own.
BACKLINKS
Backlinks are simply links from other websites back to your own site.
Backlinking can be an entire marketing strategy in itself and I
recommend that you consistently work on this aspect. The idea is that
in addition to the content of your site, search engines look at who you
are associated with – which, and how many sites are linking to you. If
sites they deem to be high quality are linking to you, this makes your
site look better in their eyes. If low-quality or ‘spammy’ sites are
linking to you, it will have an adverse effect.
So, as with all popularity contests, it’s all about the company you
keep.
Swapping links with blogs and other sites can be a good way to get
backlinks and increase traffic. However, you want to be selective about
your links and choose only relevant sites to link with. Don’t associate
yourself with a site that has a lot of ‘spammy’ links in their link
directory, or that does not have good, regularly updated content. This
is the equivalent of being guilty by association.
You can strategize by Googling the keywords you are targeting and
trying to get the top ranked sites to link to you. If your site is brand
new it might be a struggle to get major sites to link to you because the
big dogs may have nothing much to gain by linking to you, rankingwise,
but if you are providing great content they may want to link to
you as a good resource for their visitors. I would recommend at first
targeting sites within your own ‘social circle’ or just above it until you
increase your own ranking, then you can start to reach out to bigger
sites with more confidence.

Build Inbound Links with Online Promotion

Now that your website is keyword-optimized, it is time to build up your inbound
links. Promoting your site to build more inbound links than your competitors, especially
from high PageRank sites, is the most important way to increase your search
engine rankings. Here are some techniques you can use to boost your inbound links
to build up the buzz and rise above the noise:
• Use XML news feeds such as RSS and Atom to automatically syndicate your content
to other sites.
• Register your feeds at news aggregators.
• Interview luminaries.
• Write articles on your most important topics for other sites, and have your bio
link back to your website.
• Create useful tools.
• Publicize new content with press releases.
• Get listed in the major directories in the appropriate category:
— http://dir.yahoo.com
— http://www.business.com
— http://www.dmoz.org
— http://botw.org
• Get listed in industry directories and resource pages (e.g., the WorkForce.com
Vendor Directory for HR software providers at http://www.workforce.com/global/
2007/vendormain07.htm).
• Get links from industry websites and discussion forums (write articles, send
press releases, post to forums, and use your link in signature files).
• Use “high-end”link

Web page optimization streamlines

Your pages to download and display faster. As
your website performance improves, your bailout rates and bandwidth bills will go
down while your conversion rates and profits will rise. In this chapter, you learned
how to minimize HTTP requests, optimize graphics and multimedia, substitute
server-side for client-side sniffing, and load JavaScript wisely.

To reduce the overhead of multiple objects that causes the majority of web page
delay, minimize the number of objects referenced within your web pages. Also, put
all of your images, still and motion, on a strict file size diet. Minimize the size of the
head of your HTML, and layer your markup to display useful content quickly and
maximize your potential search engine rankings. Finally, move your CSS to the top
and your scripts to the bottom of your pages to enable progressive display.

Top Search Engine Ranking Factors

PageRank is not the only factor that Google uses to rank search results. Google uses
more than 200 “signals”to calculate the rank of a page.a According to a survey of SEO
experts, the top 10 most important factors include the following:
• Keyword use in title tag
• Anchor text of inbound link
• Global link popularity of site
• Age of site
• Link popularity within the site’s internal link structure
• Topical relevance of inbound links to site
• Link popularity of site in topical community
• Keyword use in body text
• Global link popularity of linking site
• Topical relationship of linking page
The top factors that negatively affect a search engine spider’s ability to crawl a page or
harm its rankings are as follows:
• Server often inaccessible to bots
• Content very similar to or duplicate of existing content in the index
• External links to low-quality/spam sites
• Duplicate title/meta tags on many pages
• Overuse of targeted keywords (indicative of stuffing/spamming)
• Participation in link schemes or actively selling links
• Very slow server response times
• Inbound links from spam sites
• Low levels of visitors to the site

SEO Testing

SEO is both an art and a science. As with any scientific discipline, it requires rigorous testing
of hypotheses. The results need to be reproducible, and you have to take an experimental
approach so as not to modify too many variables at once. Otherwise, you will not be able to
tell which changes were responsible for the results.

And although you can glean a tremendous amount of knowledge of SEO best practices, latest
trends, and tactics from SEO blogs, forums, and e-books, it is hard to separate the wheat from
the chaff and to know with any degree of certainty that an SEO-related claim will hold true.
That’s where the testing of your SEO comes in: proving what works and what doesn’t.
Unlike multivariate testing for optimizing conversion rates, where many experiments can be
run in parallel, SEO testing requires a serial approach. Everything must filter through the
search engines before the impact can be gauged.

AdWords Tips For SEO

Observe and track your competition
Observe the competition. Write a script to track ads of your targeted keyword list.
Record competitor ads for several weeks. Note changes in ads. Analyze ads that
changed. If the ads are not changing, this could mean they are working.

Experiment
Don’t stop with weeding out the nonworking keywords. Experiment with new keywords.
Learn of any new competitors. Learn what their keywords are. Don’t be afraid
to gradually lower your bid prices to see the effects on your CTR.

Refine your ad copy
A poor CTR usually means bad ad copy, bad keyword targeting, and bad timing. You
can easily create several versions of your ads for your campaign. Use that to your advantage.
Learn which ads are converting and which are not. Learn which words are
being used in the ads that work and in the ads that do not. In general, the higher your
CTR, the lower your average cost-per-click will be.

Try other platforms
If you have stiff competition on AdWords, you may want to examine other PPC platforms.
Yes, search volumes may be lower, but less competition and more keywords of
interest could compensate for the lack of volume.
If you score a successful campaign with ads producing clicks and, ultimately, profits,
you may want to consider replicating the campaign across the other platforms—
especially Yahoo! and Microsoft. Replicating your winning formula is smart marketing.

SEO Benefits Of A Quality Website Structure

The main benefits of having a great navigation structure for both search engines and people
are:

Indexation - If the search engines such as Google can follow your structure from Homepage
right down to the lowest levels, then it will get to “crawl” (see) every page on the site. It means
that as long as the rest of the site is optimized correctly, every page on the site should be
indexed in the search engines.
Following on from this, any new pages you add should get indexed more quickly as the site can
be crawled more easily.
Usability - It gives a better impression of the website to the search engine due to its usability
for humans. Big search engines look for this mainly.
You should always focus at designing a simple website structure, as you should be going to
innumerable unknown users.
Page

SEO Research and Analysis

even more challenging and complex by the constant evolution of best practices and
optimization opportunities.
Fortunately, a great variety of resources that make the job easier are available on the Web.
Many leading SEO practitioners regularly post their thoughts on blogs or in forums, or speak
at conferences. This creates many opportunities to interact with them, learn from their
experience, and keep your skills sharp and up-to-date.
In this chapter, we will talk about those resources and how to leverage them to be more
successful in your SEO efforts.

SEO is rapidly evolving. Search engines are constantly changing their algorithms, and new
media and technologies are being introduced to the Web on a regular basis. Staying current
requires an ongoing commitment to research.


One of the easiest ways to research what is happening in the world of SEO is to study the
websites and periodicals that cover SEO in detail, but ongoing testing of SEO hypotheses should
also play a role.

SEO for Lead Generation and Direct Marketing

Although lead generation via the Web is less direct than an e-commerce transaction, it is
arguably just as valuable and important for building customers, revenue, and long-term value.
Millions of search queries have commercial intents that can’t be (or currently aren’t) fulfilled
directly online. These can include searches for services such as legal consulting, contract
construction, commercial loan requests, alternative energy providers, or virtually any service
or product people source via the Web.
Here are some factors to think about when considering SEO for lead generation and direct
marketing:

When to employ
Use it when you have a non-e-commerce product/service/goal that you want users to
accomplish on your site or for which you are hoping to attract inquiries/direct contact
over the Web.

Keyword targeting
As with e-commerce, choose phrases that convert well, have reasonable traffic, and have
previously performed in PPC campaigns.

Page and content creation/optimization
Although you might think it would be easier to rank high in the SERPs for lead generation
programs than for e-commerce, it is often equally challenging. You’ll need a solid
combination of on-site optimization and external link building to many different pages on
the site (with good anchor text) to be competitive in the more challenging arenas.

Search Ranking Algorithm-Social sharing data

Include social sharing and follow buttons on your site, your blog, and in
your emails

social sharing strategies increase traffic and increase profits. For
those internet marketers wondering how big can social media be in terms

of helping businesses online explode

 Twitter Followers -> Email Subscribers: Twitter is a great communication

channel. It helps you contact and stay in touch with anyone you want. But

it doesn’t directly make you real money. Email marketing is still the

most profitable online marketing channel.


Facebook Fans -> People Talking About This: Facebook’s EdgeRank was

designed to keep companies from spamming their “fans”. So it only allows

you to reach the fans that actively engage with your brand. “People

Talking About This” is the closest metric you have to increase your

“viral reach”. The higher that number goes, the better chance you have of

reaching more people. And the bigger your page will grow because you’ll

start reaching more “friends of fans”.

Techniques To Improve Page Rank

You can follow up certain methods for improving your page rank. One of the very common
methods followed often for this purpose is to increase the numbers of pages of the website and
interlinking them with each other. However, you need to take care so that your website is
significant and it contains meaningful content for use. Otherwise, your website may obtain a
negative ranking in the search engines if your website has empty pages without any particular
substance.

Link building is another method for improving page ranking. The incoming backlinks play
significant role in this direction. It is again a mathematical formula for improving page rank. A
high ranked page link certainly improves your page ranking. Some other advertising strategies
can also help you out in this direction.

Page ranking has utmost importance for your website. A high page ranked website always
attains higher page rank backlinks. However, this depends on other traits of your website like
quality content and other services.

SEO for Raw Traffic

Optimizing a site for search engines and creating keyword-targeted content helps a site rank
for key search terms, which typically leads to direct traffic and referring links as more and more
people find, use, and enjoy what you’ve produced. Thousands of sites on the Web leverage
this traffic to serve advertising, directly monetizing the traffic sent from the engines. From
banner ads to contextual services such as Google’s AdSense program to affiliate programs and
beyond, web advertising has become a massive industry—$25 billion plus, according to
eMarketer.

Here are some factors to think about when considering SEO for raw traffic:
When to employ
Use it when you can monetize traffic without actions or financial transactions on your site
(usually through advertising).
Keyword targeting
Keyword targeting in this scenario can be very broad. The goal here isn’t typically to select
specific keywords, but rather to create lots of high-quality content that naturally targets
interesting/searched-for terms. Instead of singular optimization on specific terms, the
focus is on accessibility and best practices throughout the site to earn traffic through both
high volume and long tail queries (for more on what long tail is, see Chapter 5).
Concentrate efforts on great content, and use keyword-based optimization only as a
secondary method to confirm the titles/headlines of the works you create.
Page and content creation/optimization
A shallow, highly crawlable link structure is critical to getting all of your content indexed—
follow good information architecture practices.You’ll also need to
employ good on-page optimization (titles, headlines, internal linking, etc.) and make your
articles easy to share and optimized for viral spreading.

SEO for Reputation Management

SEO for reputation management is a process for neutralizing negative mentions of your name
in the SERPs. In this type of SEO project, you would strive to occupy additional spots in the
top 10 results to push the critical listing lower and hopefully off the first page. You may
accomplish this using social media, major media, bloggers, your own sites and subdomains,
and various other tactics.


Since one’s own name—whether personal or corporate—is one’s identity, establishing and
maintaining the reputation associated with that identity is generally of great interest.
Imagine that you search for your brand name in a search engine and high up in the search
results is a web page that is highly critical of your organization.

SEO for E-Commerce Sales

One of the most direct monetization strategies for SEO is driving relevant traffic to an ecommerce
shop to boost sales. Search traffic is among the best quality available on the Web,
primarily because a search user has expressed a specific goal through her query, and when this
matches a product or brand the web store carries, conversion rates are often extremely high.

When to employ
Use it when you have products/services that are directly for sale on your website.
Keyword targeting
Paid search advertising is an excellent way to test the efficacy and potential ROI of keyword
targets. Find those that have reasonable traffic and convert well, and then pursue them
further. You’ll often find that the more specific the query—brand-inclusive, productinclusive,
and so on—the more likely the visitors are to make the purchase.
Page and content creation/optimization
You’ll typically need some serious link building, along with internal optimization, to
achieve high rankings for competitive, high-value keywords that bring in conversionfocused
traffic. Manual link building is an option here, but scalable strategies that leverage
a community or customers can be equally, or even more, valuable.

Javascript Math object

The Math object holds a set of constants and methods enabling more complex mathematical operations than the basic arithmetic operators

var root = Math.sqrt(10);


Constants Provided by the Math Object
Property
Description
Math.E
The base of the natural logarithm (Euler's constant e)
Math.LN2
Natural log of 2
Math.LN10
Natural log of 10
Math.LOG2E
Log (base 2) of e
Math.LOG10E
Log (base 10) of e
Math.PI
Pi (p)
Math.SQRT1_2
Square root of 0.5 (equivalently, one over the square root of 2)
Math.SQRT2
Square root of 2
Table 7-4: Methods Provided by the Math Object
Method
Returns
Math.abs(arg)
Absolute value of arg
Math.acos(arg)
Arc cosine of arg
Math.asin(arg)
Arc sine of arg
Math.atan(arg)
Arc tangent of arg
Math.atan2(y, x)
Angle between the x axis and the point (x, y), measured counterclockwise (like polar coordinates). Note how y is passed as the first argument rather than the second.
Math.ceil(arg)
Ceiling of arg (smallest integer greater than or equal to arg)
Math.cos(arg)
Cosine of arg
Math.exp(arg)
e to arg power
Math.floor(arg)
Floor of arg (greatest integer less than or equal to arg)
Math.log(arg)
Natural log of arg (log base e of arg)
Math.max(arg1, arg2)
The greater of arg1 or arg2
Math.min(arg1, arg2)
The lesser of arg1 or arg2
Math.pow(arg1, arg2)
arg1 to the arg2 power
Math.random()
A random number in the interval [0,1]
Math.round(arg)
The result of rounding arg to the nearest integer. If the decimal portion of arg is greater than or equal to .5, it is rounded up. Otherwise, arg is rounded down.
Math.sin(arg)
Sine of arg
Math.sqrt(arg)
Square root of arg
Math.tan(arg)
Tangent of arg
There are several aspects of the Math object that need to be kept in mind. The trigonometric methods work in radians, so you need to multiply any degree measurements by p / 180 before using them. Also, because of the imprecise characteristic of floating-point operations, you might notice minor deviations from the results you expect. For example, though the sine of p is 0, the following code:
alert(Math.sin(Math.PI));

JavaScript and XML

To demonstrate JavaScript, XML, and the DOM in action, let’s use Internet Explorer 5.5 or better to load an XML document containing our employee directory and see if we can manipulate it. First, to load in the document we create an instantiation of Microsoft’s XML parser using the JScript-specific ActiveXobject. Once the object is created, we load the appropriate XML document into memory. In this case, it is the pure XML file of employee records we saw earlier without style sheets or other references.
var xmldoc = new ActiveXObject("Microsoft.XMLDOM");

xmldoc.async = false;

xmldoc.load("staff2.xml");
Once loaded, we can then use the DOM to manipulate it. For example, we can access the root element of the document (<<directory>>) using
var rootElement = xmldoc.documentElement;
then we might alert out its nodeName property as shown in this example.
<<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">>

<<html xmlns="http://www.w3.org/1999/xhtml">>

<<head>>

<<title>>XML Demo<</title>>

<<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />>

<</head>>

<<body>>

<<script type="text/jscript">>

<<!--

 var xmldoc = new ActiveXObject("Microsoft.XMLDOM");

 xmldoc.async = false;

 xmldoc.load("staff.xml");



 var rootElement = xmldoc.documentElement;

//-->>

<</script>>

<<form action="#" method="get">>

 <<input type="button" value="show node"

 onclick="alert(rootElement.nodeName);" />>

<</form>>

<</body>>

<</html>>
 
 
 
 
 
 
function deleteLastElement()

{

  var rootElement = xmldoc.documentElement;

  if (rootElement.hasChildNodes())

     rootElement.removeChild(rootElement.lastChild);

}
 
 
 
Really the only difference here is the use of the xmldoc object we created to reference the XML document rather than just plain document, which would reference the HTML Document object. Otherwise, the manipulations are the same as with HTML.
 

Javascript Image Objects

Properties of Image Objects
Property
Description
align
Indicates the alignment of the image, usually “left” or “right.”
alt
The alternative text rendering for the image as set by the alt attribute.
border
The width of the border around the image in pixels.
complete
Non-standard (but well-supported) Boolean indicating whether the image has completed loading.
height
The height of the image in pixels or as a percentage value.
hspace
The horizontal space around the image in pixels.
isMap
Boolean value indicating presence of the ismap attribute, which indicates the image is a server-side image map. The useMap property is used more often today.
longDesc
The value of the (X)HTML longdesc attribute, which provides a more verbose description for the image than the alt attribute.
lowSrc
The URL of the “low source” image as set by the lowsrc attribute. Under early browsers, this is specified by the lowsrc property.
name
The value of the name attribute for the image.
src
The URL of the image.
useMap
The URL of the client-side image map if the <img> tag has a usemap attribute.
vspace
The vertical space in pixels around the image.
width
The width of the image in pixels or as a percentage value.
The traditional Image object also supports onabort, onerror, and onload event handlers. The onabort handler is invoked when the user aborts the loading of the image, usually by clicking the browser’s Stop button. The onerror handler is fired when an error occurs during image loading. The onload handler is, of course, fired once the image has loaded. Under modern browser implementations that support (X)HTML properly, you will also find onmouseover, onmouseout, onclick, and the rest of the core events supported for Image.

Javascript The + Operator

The binary + operator adds numeric operands or concatenates string operands:

1 + 2 // => 3
"hello" + " " + "there" // => "hello there"
"1" + "2" // => "12"

When the values of both operands are numbers, or are both strings, then it is obvious
what the + operator does. In any other case, however, type conversion is necessary, and
the operation to be performed depends on the conversion performed. The conversions
rules for + give priority to string concatenation: if either of the operands is a string or
an object that converts to a string, the other operand is converted to a string and concatenation
is performed.

Javascript Recursion

Recursion is when a function calls itself. This is often useful in mathematics,
such as fi nding the nth number in the Fibonacci series (1, 2, 3, 5,
8, 13, 21…).
function fi bonacci(n) {
if ( n < 2 ) {
return 1;
} else {
return fi bonacci(n-2) + fi bonacci(n-1);
}
}
fi bonacci(5);
8
fi bonacci(10);
89

Javascript Objects as Arguments

You may want to write functions that take many arguments, some of
which are optional.
function drawElement( color, border, width, height,
left, top, zIndex) {
// Make and display an element with these variables
}
drawElement("red", 4, null, null, 100, 10);
Function signatures like this aren’t ideal for a couple of reasons:
■ It’s hard to remember the exact order of arguments.
■ You have to specify null values when you want to use the default
value for arguments in the middle of the signature.
■ Did you notice that I forgot to specify a value for zIndex? It’s hard to
count all those arguments correctly!
Passing multiple values in a single object is often a better solution:
function drawElement(options) {
// Make and display an element with the values in options
}
drawElement({
color: "red",
border: 4,
left: 100,
top: 10
});
Specifying default values is a little bit trickier with this technique. You’ll
need to create an object holding all the defaults and merge it with the
options object.

Javascript search

search(regexp)
The search() method is the same as indexOf() except that it takes a
regular expression pattern instead of a substring. It also returns -1 if the
pattern isn’t found.
"hello world".search(/[aeiou]/); // Find the fi rst vowel
1
"hello world".search(/\d/); // Find the fi rst digit
-1
match(regexp)
The match() method returns an array containing all the substrings
matching the regular expression and its subpatterns. Unlike the other
search-and-replace methods, it returns null if the pattern doesn’t match.
Here are some simple examples, but I’ll cover this function more in
Chapter 8:
// Find all the vowels
"hello world".match(/[aeiou]/g);
["e", "o", "o"]
// Find "world" regardless of capitalization
"hElLo WoRlD".match(/world/i);
["WoRlD"]
replace(pattern, replacement)
The replace() method works like match() except that it returns a string
with all instances of pattern replaced by the string replacement.
// Remove all non-numeric characters from a phone number
"(310) 555-9876".replace(/\D/g, "");