Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

129
Views
How do I make separate hover functions work in javascript?

I'm trying to make an image {image 7} appear when hovering over {image 5} while also making {image 8} appear when hovering over {image 6}. It seems to work fine when using the hovering only once, but when I try to do it twice (make different images appear when hovering on different images), it doesn't work. I think that it is because i don't know how to call each set of images on script properly. I'm pretty new at this so any help would be super appreciated. Thank you in advaced!

p.s. I will use the hover event for diferent elements several times in my webpage, not just twice.

here is my html:

<div class="row1">

<div>
<div class="hover-title">

<a rel="history" href="enlightened-type" class="image-link" id="what" onmouseover="showImg()" onmouseout="hideImg()">{image 5 scale="19"}</a>

</div>

<div class="hover-image">
<div id="what1" style="visibility: hidden;"> {image 7 scale="27"} </div>
</div>

</div>

<div>

<div class="hover-title">
<a rel="history" href="enlightened-type" class="image-link" id="young" onmouseover="showImg()" onmouseout="hideImg()">{image 6 scale="16"}</a>
</div>

<div class="hover-image">
<div id="young1" style="visibility: hidden;">{image 8 scale="12"} </div>
</div>

</div>

& this is my script:

<script>

    var hoverImg = 
        document.getElementById("what1");
        document.getElementById("young1");

    function showImg(x) {
      hoverImg.style.visibility = "visible";
    }

    function hideImg(x) {
      hoverImg.style.visibility = "hidden";
    }
  
 
</script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think you should add the sender to the event handler and edit the related element

In html you should do this

<a rel="history" href="enlightened-type" class="image-link" id="what" onmouseover="showImg(this)" onmouseout="hideImg(this)">{image 5 scale="19"}</a>

And in Js

function showImg(x) {
  document.getElementById(x.id + "1").style.visibility = "visible";
}

function hideImg(x) {
  document.getElementById(x.id + "1").style.visibility = "hidden";
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!