Skip to content

Trigger click on SVG image

I’m having a play with a SVG image to see if I can create a map for my website. I grabbed the image from a 3rd party site, and now I’m just trying to implement it. Here is a fiddle of what I have:

So basically the CSS is:

svg, svg * {
    pointer-events: none;
#map {
  display: block;
  text-indent: -9999px;
  width: 100% ;
  height: 600px;


<!DOCTYPE html>
<html lang="en">

    <div id="mapContainer">
        <object id="map" data="" type="image/svg+xml"></object>


..and then I’m trying to capture the clicks with:

document.getElementById("FR-A").addEventListener('click', function (event) { test() });

The paths in the SVG look something like:

<path id="FR-A" title="Alsace" class="land"

Am I misunderstanding how you capture a click on a div? Basically I need to grab the value of “title” from the path clicked on, and then my JS can work out where to send the user.




You’ll need to load the SVG into the page’s DOM if you want to attach your event listener to shapes within it, otherwise your JS won’t be able to see them.

One way to do this is to cut and paste the SVG into your HTML. Another way is to load the SVG’s DOM into a wrapper element – such as a DIV – through JS / jQuery:

<div id="mapContainer"></div>

$(function() {
  $('#mapContainer').load("", function() {
    $("#FR-A").click(function(event) {

(Apologies for the jQuery; my JS is a little rusty.)

Note that I have this inside the DOM loaded block to make sure it runs only after the #mapContainer is loaded. You can see this in action on the Interspan website. Instead of clicking, hover over the logo in the top left corner. The principle is the same, it’s just using the hover event instead of the click event.