Alert Message on Mouse Hover Over a Div Using JavaScript

javascript-alert-mouseover

In this JavaScript tutorial we will learn how to create an alert popup box when user / visitor mouse over (hover) over a div region.

JavaScript Code

Let’s create a JavaScript function that will create an alert popup message box.

1
2
3
function boxHover() {
  alert("You have mouse over the box");
}

HTML

Now we will create a div region and call the above function on mouse over (hover).

1
<div id="box" onmouseover="boxHover()"></div>

CSS

Let’s give some length and width to our div region.

1
2
3
4
5
#box {
  width: 100%;
  height: 300px;
  background: yellow;
}

Done!!

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *