Reputation: 3364
I have circles on my webpage by the id circle
. Now, what I want is when the mouse hovers over the circle, a message should be displayed.
Here's my code in javascript file:
document.getElementById("circle").onmouseover=function(){
var information = document.getElementById("toast");
message = "hello";
if (alert == null){
var toastHTML = '<div id="toast">' + message + '</div>';
document.body.insertAdjacentHTML('beforeEnd', toastHTML);
}
else
information.style.opacity = 0.9;
intervalCounter = setInterval("hideToast",1000);
};
But there seems to be some error, the javascript terminal gives:
Uncaught TypeError: Cannot set property 'onmouseover' of null
Upvotes: 0
Views: 3332
Reputation: 146239
Wrap your code in onload
event like
window.onload=function(){
document.getElementById("cicrle").onmouseover=function(){
// code goes here
};
};
Upvotes: 1