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 7576551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:56:58+00:00 2026-05-30T16:56:58+00:00

I have to create the effect of bordered when I hover over element and

  • 0

I have to create the effect of bordered when I hover over element and vice versa.

I managed to do it, but the problem is that every time I hover over one of those elements I cancel the hovering effect on the element I was hovering over.

When I hover over with id=”12345img” gets border and with id=”12345a” gets color effect. When I do it vice versa it also works, but only for the first time I’m hovering over it.

This is the code.

<script type="text/javascript">
    $(document).ready(function () {

        $('.portfolioProject a').hover(function () {
            var idElement = this.id;
            $("#" + idElement.replace('a', '') + "img").css('border', '2px solid #cdfc5d');
            $("#" + idElement + "a").css('color', '#cdfc5d');
        });

        $('.portfolioProject a').mouseleave(function () {
            var idElement = this.id
            $("#" + idElement.replace('a', '') + "img").css('border', 'none');
            $("#" + idElement + "a").css('color', 'white');
        });

        $('.portfolioImage img').hover(function () {
            var idElement = this.id;
            $("#" + idElement.replace('img', '') + "a").css('color', '#cdfc5d');
            $("#" + idElement + "img").css('border', '2px solid #cdfc5d');
        });

        $('.portfolioImage img').mouseleave(function () {
            var idElement = this.id
            $("#" + idElement.replace('img', '') + "a").css('color', 'white');
            $("#" + idElement + "img").css('border', 'none');
        });
    });
</script>

My question is how to fix it to make it work every time.

jsFiddle link

  • 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-05-30T16:56:59+00:00Added an answer on May 30, 2026 at 4:56 pm

    I think you have to create CSS class for the mouse hover effect, Then you just Have to Toggle the class on event:

    Jquery:

    $(document).ready(function () {
        $(".portfolioImageWrapper").on('mouseenter mouseleave', ".img", function () {
                      $(this).toggleClass('imgHover');
                      $("#" + (this.id).replace('img', '') + "a").toggleClass('imgHover');  
                  });
            });
    

    HTML:

    <div class='portfolioProject'>
        <ul>
            <h2>
                <li>
        <a id='7a' href='#'> Link1</a>
                </li>
            </h2>
            <h2>
                <li>
                    <a id='8a' href='#'> Link 2 </a>
                </li>
            </h2>
        </ul>
    </div>
    <div class='portfolioImageWrapper'>
        <div class='portfolioImage'><a href='#'><img class="img" src='#' alt='Image1' title='Image 1' id='7img' /></a></div><div class='portfolioImage'><a href='#'><img class="img" src='#' alt='Image 2' title='Image2' id='8img' /></a></div></div>
    

    ​CSS:

        .imgHover
    {
        border-style: dotted;
        border-width: 1px;
        color: red;
        text-decoration: none;
    }​
    

    jsfiddle

    You can toggle a different css class to your links for sure. Just modify this in jquery code (in the toggleClass function) and add the class to the css part

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

Sidebar

Related Questions

I'm trying to create an effect where when you hover over a list item
I have create my own NSOpenGLView class, right now the data that i want
I use TcxGrid I have create fields on execution time because I have a
I have to create a site definition for a client that must contain pre-defined
I am trying to create an effect when you place the mouse cursor over
I'm trying to create an effect where if the user hovers the mouse over
I am looking to create an effect like that which is used on The
I have one huge array and I'm trying to create an animation effect. My
I have create the snow effect with the linked tutorial, basically it manipulates the
I'm trying to create an effect that works in a queue, so that each

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.