Avatar of Refael
Refael
Flag for United States of America asked on

jquery function

Hello Experts,

I am trying to create a function in jquery.
The code below show you an map-area-shape ID and a DIV with an ID that correspond to the  map-area-shape.
Since i will have like 30 map-area-shape ID's and content corresponding ID's i need a function so that each time a user mouseenter the map-area it shows the corresponding content div.

<map name="Map" id="Map">
    <area shape="rect" id="we212" coords="170,11,275,51" />
</map>

<div id="we212_info">
  // content //
</div>

Open in new window



At the moment i have the below code which  i need to convert to a function.

$('#we212').mouseenter(function() {
		$('#we212_info').stop(true, true).fadeIn('slow');
		}).mouseleave(function() {
	    $('#we212_info').stop(true, true).hide();
	});

Open in new window


i will appreciate your help!
jQueryJavaScript

Avatar of undefined
Last Comment
Refael

8/22/2022 - Mon
Jon Norman

Try this (hope I got the selectors right):

$('#Map>area').each(function(){
  $(this).mouseenter(function() {
    $("#"+$(this).attr("id")+"_info").stop(true, true).fadeIn("slow");
  }).mouseleave(function() {
    $("#"+$(this).attr("id")+"_info").stop(true, true).hide();
  });
});

Open in new window

ASKER CERTIFIED SOLUTION
Jon Norman

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Refael

ASKER
Hi JonNorman, thank you, it works :-)
something to learn! than you.
Refael

ASKER
simply an expert!
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes