sudeepdino008
sudeepdino008

Reputation: 3364

using onmouseover to call a function

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

Answers (1)

The Alpha
The Alpha

Reputation: 146239

Wrap your code in onload event like

window.onload=function(){
    document.getElementById("cicrle").onmouseover=function(){
        // code goes here
    };
};

Upvotes: 1

Related Questions