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

331
Views
What is the difference between mouseover & onmouseover in JavaScript?

I am a novice JavaScript programmer. Can someone make me understand how this works?

What is the difference between mouseover & onmouseover in JavaScript? Can we interchange its use? If not, how do we know which one to use where?

mouseover example:

function showAlert() {}
button.addEventListener('mouseover', showAlert);

onmouseover example:

function changeColor() {} 
titleHeader.onmouseover = changeColor;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Basically both of them is same according to what they do , but the differences arises when we talk about what the do. you can use anyone out of them as per your wish but the addEventListener() method is not supported in Internet Explorer 8 and earlier versions which is required when you want to use mouseover. Syntax of addEventListener() which is dom element is addEventListener(event, function)

event(required)-> A String that specifies the name of the event. Note : Do not use the "on" prefix. For example, use "mouseover" instead of "mouseover". function(required)->Specifies the function to run when the event occurs. eg:

    <html>
    <body>

    <p>This example uses the addEventListener() method to attach a "mouseover" and "mouseout" event to a h1 element.</p>

    <h1 id="demo">Mouse over me</h1>

    <script>
    document.getElementById("demo").addEventListener("mouseover", mouseOver);
    function mouseOver() {
    document.getElementById("demo").style.color = "red";
    }
    </script>
    </body>
    </html>
**Dom Event onmouseover**
    <body>
    <h1 id="demo">Mouse over me</h1>
    <script>
    document.getElementById("demo").onmouseover = function(){mouseOver()};

    function mouseOver() {
     document.getElementById("demo").style.color = "red";
    }
    </script>
    </body>

At last I will like to add that you can use addEventListener inside script only you cant use it inside your html body howerver in case of Dom event you can use it inside html also using syntax like Eg:

    <html>
    <body>
    <p>This example demonstrates how to assign an "onmouseover" and "onmouseout" 
    event to a h1 element.</p>
    <h1 id="demo" onmouseover="mouseOver()" >Mouse over me</h1>
    <script>
    function mouseOver() {
     document.getElementById("demo").style.color = "red";
    }
    </script>
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!