JavaScript > Events

Onmouseover in JavaScript

How to execute a function when user mouse hover an element in JavaScript?

In case we want to execute a function when user mouse over an element, we can follow this approach.

Enter your name:
   <input type="text" name="txtName" id="txtName" />
   <input type="button" id="btn" name="btn" value="Submit" onmouseover="CallFunction(" />

        function CallFunction(id) {
            document.getElementById(id).style.background = "#c0c0c0";

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


 Views: 4515 | Post Order: 38

Write for us

Hosting Recommendations