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

120
Views
Change Click Function to hover (Vanilla Javascript)

I am using this code:

document.addEventListener("DOMContentLoaded", function(event) {

    document.getElementById("div#logo1").onclick = function(){
        hideAllImages();
        document.getElementById("01").style.display="block";
        removeNavHighlight();
        document.getElementById("div#logo1").classList.add("my_active");
    };
    
    document.getElementById("div#logo2").onclick = function(){
        hideAllImages();
        document.getElementById("02").style.display="block";
        removeNavHighlight();
        document.getElementById("div#logo2").classList.add("my_active");
    };
        document.getElementById("div#logo3").onclick = function(){
        hideAllImages();
        document.getElementById("03").style.display="block";
        removeNavHighlight();
        document.getElementById("div#logo3").classList.add("my_active");
    };

function hideAllImages() {
    var items = document.getElementsByClassName('changing_text');
    var itemsLen = items.length;
    for(var i = 0; i < itemsLen; i++) {
        items[i].style.display="none";
    }
}});

Which working fine with click event but I want to convert it to be functional when I hover to the element.

What this function must to: for example, when I hover on an image other element must appear and previous element must become hidden.

This is Vanilla Javascript code.

Any suggestions? tried to change .onclick to .onmouseover but not working

Thank you

almost 4 years ago · Santiago Trujillo
3 answers
Answer question

0

It's not .mouseover it's .onmouseover

almost 4 years ago · Santiago Trujillo Report

0

Is it working for you to replace .onclick by .onmouseover?

almost 4 years ago · Santiago Trujillo Report

0

These functions are always in format on<event>. It should be .onmouseover as the other answers have already said. Note that you'd be using mouseover if you were adding an event listener using the addEventListener function.

almost 4 years ago · Santiago Trujillo 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!