Call function when mouseover div

I’m trying to get a function to call when a user has mouseover a div (or table or form)

Onfocus doesn’t seem to work. How can I achieve this?

You’re going to want to set the div’s onmouseover attribute equal to a function. For example, if your div has an id of “thediv”, you can attach a function to its onmouseover event like this:


document.getElementById("thediv").onmouseover = function() {
  // code to run when the user hovers over the div
};

Or if you’ve already defined a function named “theFunc”, you can do it like this:


function theFunc() {
  // code to run when the user hovers over the div
}

// Make sure not to put parentheses after the function name on the following line
document.getElementById("thediv").onmouseover = theFunc;

If i wanted to do with jquery and using mouseEnter as i only want it to fire once on going over the div?

$(‘div#mydiv’).mouseEnter(function() {
dofunc(); // call my funtion
});

This doesn’t seem to work?

The ‘E’ in ‘Enter’ should be lowercase, from what I can tell in the jQuery documentation.