JavaScript Image Maps

|  | Search W3Schools : |

HOME | HTML | CSS | XML | JAVASCRIPT | ASP | PHP | SQL | MORE... |  | References | Examples | Forum | About

ADVERTISEMENTS XML Certification Download XML editor Custom Programming |  |

Table of contents

JS Basic
JS HOME
JS Introduction
JS How To
JS Where To
JS Statements
JS Comments
JS Variables
JS Operators
JS Comparisons
JS If...Else
JS Switch
JS Popup Boxes
JS Functions
JS For Loop
JS While Loop
JS Break Loops
JS For...In
JS Events
JS Try...Catch
JS Throw
JS onerror
JS Special Text
JS Guidelines
JS Objects
JS Objects Intro
JS String
JS Date
JS Array
JS Boolean
JS Math
JS RegExp
JS HTML DOM
JS Advanced
JS Browser
JS Cookies
JS Validation
JS Animation
JS Image Maps
JS Timing
JS Create Object
JS Summary
Examples/Quiz
JS Examples
JS Object Examples
JS DOM Examples
JS Quiz
JS Exam
JS References
JS Objects
JS HTML DOM

Selected Reading

Web Statistics
Web Glossary
Web Hosting
Web Quality
W3Schools Tutorials
W3Schools Forum
Helping W3Schools

# JavaScript Image Maps

An image-map is an image with clickable regions.

## Examples

Simple HTML Image map

Image map with added JavaScript

## HTML Image Maps

From our HTML tutorial we have learned that an image-map is an image with clickable regions. Normally, each region has an associated hyperlink. Clicking on one of the regions takes you to the associated link.

### Example

The example below demonstrates how to create an HTML image map, with clickable regions. Each of the regions is a hyperlink:

    <img src ="planets.gif"
    width ="145" height ="126"
    alt="Planets"
    usemap ="#planetmap" />

    <map id ="planetmap"
    name="planetmap">
    <area shape ="rect" coords ="0,0,82,126"
      href ="sun.htm" target ="_blank"
      alt="Sun" />
    <area shape ="circle" coords ="90,58,3"
      href ="mercur.htm" target ="_blank"
      alt="Mercury" />
    <area shape ="circle" coords ="124,58,8"
      href ="venus.htm" target ="_blank"
      alt="Venus" />
    </map>

### Result

## Adding some JavaScript

We can add events (that can call a JavaScript) to the <area> tags inside the image map. The <area> tag supports the onClick, onDblClick, onMouseDown, onMouseUp, onMouseOver, onMouseMove, onMouseOut, onKeyPress, onKeyDown, onKeyUp, onFocus, and onBlur events.

Here's the above example, with some JavaScript added:

    <html>
    <head>
    <script type="text/javascript">
    function writeText(txt)
    {
    document.getElementById("desc").innerHTML=txt;
    }
    </script>
    </head>

    <body>
    <img src="planets.gif" width="145" height="126"
    alt="Planets" usemap="#planetmap" />

    <map id ="planetmap" name="planetmap">
    <area shape ="rect" coords ="0,0,82,126"
    onMouseOver="writeText('The Sun and the gas giant
    planets like Jupiter are by far the largest objects
    in our Solar System.')"
    href ="sun.htm" target ="_blank" alt="Sun" />

    <area shape ="circle" coords ="90,58,3"
    onMouseOver="writeText('The planet Mercury is very
    difficult to study from the Earth because it is
    always so close to the Sun.')"
    href ="mercur.htm" target ="_blank" alt="Mercury" />

    <area shape ="circle" coords ="124,58,8"
    onMouseOver="writeText('Until the 1960s, Venus was
    often considered a twin sister to the Earth because
    Venus is the nearest planet to us, and because the
    two planets seem to share many characteristics.')"
    href ="venus.htm" target ="_blank" alt="Venus" />
    </map>

    <p id="desc"></p>

    </body>
    </html>

## Get Your Diploma!

W3Schools' Online Certification Program is the perfect solution for busy professionals who need to balance work, family, and career building.

The HTML Certificate is for developers who want to document their knowledge of HTML, XHTML, and CSS.

The JavaScript Certificate is for developers who want to document their knowledge of JavaScript and the HTML DOM.

The XML Certificate is for developers who want to document their knowledge of XML, XML DOM and XSLT.

The ASP Certificate is for developers who want to document their knowledge of ASP, SQL, and ADO.

The PHP Certificate is for developers who want to document their knowledge of PHP and SQL (MySQL).

WEB HOSTING
Web based charting for ASP.NET
$15 Domain Name Registration Save $20 / year!
Buy UK Domain Names Register Domain Names
Cheap Domain Names Cheap Web Hosting
Best Web Hosting
PHP MySQL Hosting
Top 10 Web Hosting
UK Reseller Hosting
Web Hosting
FREE Web Hosting

WEB BUILDING
Website Templates Flash Templates Website Builder Internet Business Opportunity
Custom Programming
FREE Trial or Demo Web Content Manager Forms,Web Alerts,RSS
Download XML editor
FREE Flash Website
FREE Web Templates

EDUCATION
US Web Design Schools
HTML Certification
JavaScript Certification
XML Certification
PHP Certification
ASP Certification

HOME or Top of Page |  | Printer Friendly
W3Schools is for training only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy. Copyright 1999-2009 by Refsnes Data. All Rights Reserved.