Skip to content
Advertisement

Can I have an onclick event on a imagemap area element?

I would like to put an onclick event on an area element. Here is my setup:

JavaScript

I have tried 2 different ways to have an onclick event. Firstly i tried this:

JavaScript

I have also tried this:

JavaScript

Neither of the above work. Do area elements support the above, or do they only support having a href?

Advertisement

Answer

Pay attention:

  1. Attribute href is obligatory, without it the area-tag does nothing!

  2. To add a click event, you’ll need to block default href.


Your code should start as follows:

JavaScript

Live example here.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement