Discover the steps for highlighting two specific areas on a map using HTML

Is it possible to select two different area maps using the HTML attribute "COORDS" with just one click?

For example:

<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<div class="map">
<MAP name="map1">
<AREA 
HREF="#"
SHAPE="poly"
ALT=""
COORDS="85,6,85,7,84,7..."/>
<AREA 
HREF="#"
SHAPE="poly"
ALT=""
COORDS="90,60,55,7,94,28..."/>
</Map>
<IMG SRC="France.png" USEMAP="#map1" />
    
</div>
</body>
</html>

I am looking to be able to select both of these areas at the same time with a single click.

Answer №1

When working in HTML, it's important to remember that only one element can be focused on at a time. However, you have the option to add a class to multiple <area> elements and style them accordingly to give the appearance of being selected.

In the example below, I demonstrate adding a click event handler to the <map> element. This listener will iterate through the <area> elements within the <map>, remove the current class name for each item, and then apply the class name "selected" if the href attribute matches with the clicked target.

<!DOCTYPE html>
<html lang="en">
<head>
<style>map .selected { border:1px dashed green; }</style>
</head>
<body>
<div class="map">
<MAP id="map1" name="map1">
<AREA HREF="#" SHAPE="poly" ALT="" COORDS="85,6,85,7,84,7..."/>
<AREA HREF="#" SHAPE="poly" ALT="" COORDS="90,60,55,7,94,28..."/>
</Map>
<IMG SRC="France.png" USEMAP="#map1" />
    
</div>
<script type="text/javascript">
var map = document.selectElementById('map1");
map.addEventListener('click',function(event) {
    var t = event.target;
    for(var i = 0; i < map.children.length; i++) {
       map.children[i].className = '';
       if(t.href == map.children[i].href)
           map.children[i].className = 'selected';
    }
});
</script>
</body>
</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Showing an individual image when a particular list item is clicked using jquery

I have created an image slider that automatically transitions between images. However, I would like to have a specific image displayed when a particular list item is clicked in the round buttons below. For example, if the slider is showing the 5th image a ...

Creating a border indentation for a table row using the <tr> tag

In my database, there is a table that shows the parent-child relationship. Check out this link for more details The HTML structure of the table is as follows: <table> <tr class="parent_row"> <td >1</td> <td>2</t ...

Styling Dynamic HTML Content in Angular: Tips and Tricks

After running this line of code, I have a generated element sub with a property of [sub]. <li [displayMode]="displayMode" template-menu-item style="cursor: pointer" [routerLink]="['/request/checkoutReview']" icon="fa-shopping-cart" name ...

When using the `display: block;` property within a `code` tag nested inside a `pre` tag, it results in unexpected line breaks and incomplete styling when scrolling

I am trying to create a zebra striped code sample using HTML and CSS. However, when I run the code snippet below, it adds unwanted new lines and does not apply the styling properly when using the scroll bar. How can I resolve this issue? <!DOCTYPE h ...

Sending multiple error messages from PHP to jQuery as an array, encoded in JSON format

Having some difficulty outputting multiple errors as arrays from my PHP file in JSON format to jQuery. Typically, PHP data can be encoded as JSON and then sent to jQuery for displaying the code as either an Ajax success or error response. Everything works ...

Encountering unsupported MIME type

I recently encountered a peculiar issue that I managed to resolve, but I'm curious as to why it occurred in the first place. My project involves node.js with express. app.get('/eventname/:event', (req, res) => { res.render('event.hb ...

Is it possible to decrease the size of a div by scrolling both vertically and horizontally?

Can a div's height and width both be reduced at the same time while scrolling down a page? Let's say that as the user scrolls, the size of the div changes from 400px by 400px to 200px by 200px, all while remaining centered on the page. I've ...

Struggling to modify a specific property of an Object using Ajax.BeginForm, only to find that all other properties on the Object become null upon submission

I am attempting to edit the PaymentNotificationEmail field using Razor Code: @using (Ajax.BeginForm("Save", "PaymentLandingPage", new AjaxOptions { HttpMethod = "Post", InsertionMode = InsertionMode.Replace, })) { <t ...

detecting click or submission actions on iOS

Below is the HTML code for a form submit that has been modified to prevent refreshing on submission. Everything seemed to be working fine, until I encountered an issue with the submit button not functioning on iOS. The onsubmit event simply wouldn't ...

Create a new tab with a specified URL when a link is clicked

When the 'Terms and Conditions' link is clicked, I want to open a new tab in the same browser with the URL: http://localH:30321/OrchardLocal/TermsAndConditions Here is what I have tried so far: <p>Accept the <a href="~/" target="_blank ...

Change the display, animate the elements within

Currently working on a landing page with a contentSwitcher and everything is functioning properly. However, I am interested in animating the contents sequentially to add some stylish flair. Take a look at the Test Landing Page for reference. If you observ ...

The use of a custom padding on a text input with the Bootstrap 3 form-control class can cause the text to be hidden

It seems like the code is working fine in Opera and Chrome, but in Firefox and IE11, the text is getting hidden, which is not very enjoyable. I don't have a Mac, so I can't test it on Safari. You can see the issue in action on this Plunker. I&a ...

A guide to handling a dynamic form with vue.js

Currently, I am working on implementing a filter option on my website where the options are dynamically loaded from the database. Due to this dynamic nature of the options, using a typical v-model approach seems challenging. The filter includes various pa ...

What are the steps to prevent the information in a text box from disappearing after submitting and calculating?

When this code is executed, it retrieves information about the starting and ending addresses and calculates the distance between them. However, a problem arises when the user submits the form - the input fields for entering the addresses are cleared. < ...

Embracing the balance of a gradient backdrop

I'm looking to create a gradient background for my page that transitions from light blue in the center to dark blue on the sides in a symmetrical way. I've tried using a linear gradient that goes from left to right, but it doesn't achieve th ...

Centered on the page vertically, two distinct sentences gracefully align without overlapping, effortlessly adjusting to different screen sizes

I had no trouble centering horizontally but I'm struggling with vertical alignment. I want these two sentences to be positioned in the middle of the page, regardless of device size. I attempted using vertical-align without success and then tried posit ...

The dividers flicker in and out of view

I have a menu with 7 elements, where clicking on an element causes its content to appear by fading in. If another element is clicked, the current content fades out and the new content fades in. I've successfully implemented this concept for 3 of the 7 ...

Retain the user's input in the text box even after the form has been submitted

Currently, I am tackling the challenge of creating a register form with an error handler to manage any mistakes made by users during registration. Once the form is submitted, potential errors are displayed to the user. To enhance user experience, I am ex ...

Creating a Visual Balance with CSS Image Margins

div#columncontents { background: black; } img.colimg03 { position: relative; right: -70px; } img.colimg02 { position: relative; right: -40px; } <div id="columncontents"> <div class="columnimage"> <img class="colimg01" src=" ...

What could be the reason why my buttons are not responding to the ActionListener?

I am encountering some difficulties in making things happen when I click a button. This is where the buttons are declared: public class DoND extends JFrame implements ActionListener { public JButton btnsuit1, btnsuit2, ... , btnsuit26; public static ...