Search code examples
javascriptcssdictionaryshapesarea

how to insert div directly in tag href area shape


I wish to know if it is possible to insert following divs

<div id="cal1"> [dopbsp id="1"  lang=it]</div>

<div id="cal2"> [dopbsp id="1"  lang=it]</div>

<div id="cal3"> [dopbsp id="1"  lang=it]</div>

directly in the tag href image map linked by different shape areas as following

<area shape="circle" coords="160,59,20" href="#">
<area shape="circle" coords="111,58,20" href="#">
<area shape="circle" coords="60,59,20"  href="#">

so that when I click on shape area, for example

<area shape="circle" coords="160,59,20" href="#">

then correspondent div, for example

<div id="cal1"> [dopbsp id="1"  lang=it]</div>

is loaded under the map image Ps: dopbsp id="1" ... is a calendar booking plugin of wordpress

Thanks


Solution

  • You cannot. <area> cannot have any child elements. See the World-wide Web compendium working draft on the area tag or the Mozilla Developer Network description for more information.

    The way to do this is to connect a given <area> with a given <div> via IDs and use JavaScript to show/hide the <div> when you click on an <area>. Along the lines of:

    <area shape="circle" coords="160,59,20" href="#id-of-div-1">
    <area shape="circle" coords="111,58,20" href="#id-of-div-2">
    <area shape="circle" coords="60,59,20"  href="#id-of-div-3">
    
    <div class="divs-to-show-hide">
     <div id="id-of-div-1">some content here</div>
     <div id="id-of-div-2">some content here</div>
     <div id="id-of-div-3">some content here</div>
    </div>
    

    jQuery

    $('area').on('click',function(e) {
     e.preventDefault();
     $(this.href).show().siblings().hide();
    });