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(this.id)" />

    <script>
        function CallFunction(id) {
            document.getElementById(id).style.background = "#c0c0c0";
        }
    </script>

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”.

OUTPUT

 Views: 4780 | Post Order: 38



Write for us






Hosting Recommendations