JavaScript onmouseover Event Example

Updated on     Kisan Patel

If we want to execute a javascript function when user mouse over an element, we need to use javascript onmouseover event.

<!-- HTML -->

<input type="button" id="btn" name="btn" value="hover mouse on me" onmouseover="TestFunction(" />

<!-- Javascript -->
<script type="text/javascript">
function TestFunction(id) {
   document.getElementById(id).style.background = "#FFF200";

In the above code snippet, we have specified onmouseover event in the button. When user mouse over this button, “TestFunction()” function executes that changes its background color to “#FFF200”.

See the Pen EjJjBX by Kisan (@pka246) on CodePen.


Leave a Reply