Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
265 views
in Technique[技术] by (71.8m points)

javascript - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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();
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...