How to call a JavaScript Function from an onmouseover Event ? Last Updated : 15 Apr, 2024 Comments Improve Suggest changes Like Article Like Report The onmouseover event in JavaScript is triggered when the mouse pointer moves onto an element, such as a button, image, or text. We will see how to call JavaScript function from an onmouseover event in various ways, like using the onmouseover Attribute and Using Event Listener. Table of Content Using onmouseover attributeUsing Event ListenerUsing the onmouseover AttributeIn this approach, we are directly adding the onmouseover attribute to an HTML element. The HTML button element utilizes the onmouseover attribute to trigger the JavaScript function greet() when the mouse hovers over it. Upon hovering, an alert message "Welcome to GeeksForGeeks!" displays the onmouseover event's usage to call a function. Example: The below example uses the onmouseover attribute to call a JavaScript function from an onmouseover Event HTML <!DOCTYPE html> <html> <head> <title>Call Function on Mouseover</title> <style> body { text-align: center; } h1 { color: green; } </style> </head> <body> <h1>GeeksForGeeks</h1> <h3> Call Function on mouseover using onmouseover attribute </h3> <button id="myButton" onmouseover="greet()"> Hover over me </button> <script> function greet() { alert('Welcome to GeeksForGeeks!'); } </script> </body> </html> Output: Using Event ListenerIn this approach, we utilize the addEventListener method to bind an event listener to an HTML element. The JavaScript function changeText() is linked to the HTML button element using the addEventListener method, activating when the mouse hovers over it. Upon hover, the text within the paragraph element with the ID "myParagraph" is dynamically altered to "This is a New text!". Example: The below example uses the addEventListener method to call a JavaScript function from an onmouseover Event. HTML <!DOCTYPE html> <html> <head> <style> body { text-align: center; } h1 { color: green; } </style> </head> <body> <h1>GeeksForGeeks</h1> <h3> Call Function on mouseover using Event Listener </h3> <button id="myButton">Hover over me</button> <p id="myParagraph">Original text</p> <script> // Function to change text on mouseover function changeText() { var paragraph = document.getElementById('myParagraph'); paragraph.textContent = 'This is a New text!'; } document.addEventListener('DOMContentLoaded', function () { // Select the button element var button = document.getElementById('myButton'); // Attach event listener for the 'mouseover' event button.addEventListener('mouseover', changeText); }); </script> </body> </html> Output: Comment More infoAdvertise with us Next Article How to call a JavaScript Function from an onmouseover Event ? yuvrajghule281 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads How to Call a JavaScript Function from an onmouseout Event ? The onmouseout event in JavaScript triggers when the mouse pointer leaves an element. This event is commonly used in web development to execute certain functions when a user moves the mouse away from a specific area on the webpage. Below are the approaches to call a JavaScript function from an onmou 3 min read How to Call a JavaScript Function from an onsubmit Event ? The onsubmit event attribute in HTML is triggered when a form is submitted. It is also useful for validating form data or performing actions before any submission and ensures better control and validation of user inputs before data is sent. The below methods can be used to call a JavaScript function 2 min read How to Call a JavaScript Function using an onsubmit Event ? HTML has a form element that is used to get the data from the user and send the data to the server. Before the HTML form sends data to the server, it generates an event called "submit". This event can be utilized to execute a JavaScript function that can either validate the form data or notify the u 3 min read How to Call a JavaScript Function from Chrome Console ? One can call a JavaScript Function from the Chrome Console. We will learn how can we call the function in the console that is written in JavaScript. Steps to call a JavaScript Function from Chrome ConsoleOpen the Chrome ConsoleYou can open the Chrome Console by right-clicking on your webpage, select 2 min read How to call function from it name stored in a string using JavaScript ? In this article, we will call a function from the string stored in a variable. There are two methods to call a function from a string stored in a variable. Using window object methodUsing eval() method Note: The eval() method is older and is deprecated. Method 1: Using the window object. The window 2 min read How to call JavaScript function in HTML ? In HTML, you can easily call JavaScript functions using event attributes like onclick and onload. Just reference the function name within these attributes to trigger it. You can also call functions directly within script blocks using standard JavaScript syntax. Let's create an HTML structure with so 2 min read How to differentiate mouse âclickâ and âdragâ event using JavaScript ? Working with web elements a user may drag or click an element as per requirement. It is important to distinguish between drag and click events. JavaScript is a high-level, dynamically typed programming language that can be used to distinguish between drag and click events. JavaScript has drag-and-cl 3 min read How to Add event listener to Button in JavaScript ? In web development adding an event listener to a button is a common task that allows us to execute JavaScript code in response to user interactions, such as clicks. This helps us to create interactive and flexible web pages. Using addEventListener()The addEventListener method is a versatile and wide 1 min read Call a Parent Window Function from an iframe Accessing a parent window's code or functions from a child window is possible. By using an iframe, a window can be opened to communicate with the parent. This guide provides simple syntax and code for calling functions in the parent window from the child window.Syntax:<a onclick="parent.abc();" h 1 min read JavaScript onmouse Events The onmouse event is used to define the operation using the mouse. JavaScript onmouse events are: onmouseover and onmouseoutonmouseup and onmousedownonmouseenter and onmouseleave JavaScript onmouseover and onmouseout: The onmouseover and onmouseout events occur when the mouse cursor is placed over s 1 min read Like