Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7986061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:44:20+00:00 2026-06-04T11:44:20+00:00

So I have been trying to write jquery that make one element become active

  • 0

So I have been trying to write jquery that make one element become active when another one is hovered. This will be used for highlighting areas on a map when a location is hovered.

I have it working for one destination using:

function engageMaps(){ 
  var destination = $(".destination .cancun"); 
  var pin = $(".image_map .cancun"); 
  $(destination).hover( 
    function () { 
      $(pin).addClass("active"); 
    }, 
    function () { 
      $(pin).removeClass("active"); 
    } 
  );
};

But i need it to work for all destinations based off of the elements class. If the classes match then they should be active.

I tried doing something like this (doesn’t work. probably written wrong)

function engageMaps(){ 
  var destination = (($(".destination").children()).attr('class')); 
  var pin = (($(".image_map").children()).attr('class'));
  if($(destination) === $(pin)){
    $(destination).hover( 
      function () { 
        $(pin).addClass("active"); 
      }, 
      function () { 
        $(pin).removeClass("active"); 
      } 
    );
  };
};

and here is the html:

<div class="image_map">
  <a class="cancun" id="cancunPin" href="#">Cancun</a>
  <a class="cozumel" id="cozumel" href="#">Cozumel</a>
</div>
<div class="destinations">
  <ul>
    <li class="destination"><a class="cancun" href="#">Cancun</a></li> 
    <li class="destination"><a class="Cozumel" href="#">Cozumel</a></li>
  </ul>
</div>

If anyone could help me that would be awesome. I hope I explained it well enough.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:44:22+00:00Added an answer on June 4, 2026 at 11:44 am

    This might do what you’re wanting. Maybe.

    http://jsfiddle.net/sUgyW/

    $('.destinations a').hover(
        function () {
            $('.image_map a.' + $(this).attr('class')).addClass('active');
        },
        function () {
            $('.image_map a').removeClass('active');
        }
    );
    

    I also tweaked your HTML slightly: changed class="Cozumel" to class="cozumel".

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to write a regex that will remove whitespace following a
I have been trying to write a set of htaccess rules that will do
I have been trying to write a constructor function that would make an object
I have been trying to write an app that periodically parses the contents of
I have been trying to write a script that may help me to comment
I have been trying to write a Controller Plugin which I will be using
I have been trying to write some applescript that checks to see if the
I'm trying to write a jQuery plugin that will provide additional functions/methods to the
I'm trying to write a jQuery script (I have never written one before and
I've been trying to write Jquery code to check if two inputs have the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.