Javascript Mouseover Element

Published 4 Jun, 2020

Reading time: 1 Mins


How to add mouseover func in Javascript

How to properly add mouseover functionality in javascript. You can add onmouseover keyword argument in the element.

<div onmouseover="processMouseOver(this)">
    Your Children Element Here.
</div>

Make sure to call this then only function accepts element as argument otherwise will be null.

This is how the javascript code look like.

function processMouseOver(element) {
    console.log(element)
}

addEventListener works only if the element is already available in the DOM. If you add new element append to the DOM then chances are the addEventListener will not work.

Read More