SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Jan 2005
    Location
    UK
    Posts
    539
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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?

  2. #2
    SitePoint Enthusiast
    Join Date
    Jun 2011
    Location
    Dartmouth, MA, USA
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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:

    Code JavaScript:
    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:

    Code JavaScript:
    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;

  3. #3
    SitePoint Evangelist
    Join Date
    Jan 2005
    Location
    UK
    Posts
    539
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  4. #4
    SitePoint Enthusiast
    Join Date
    Jun 2011
    Location
    Dartmouth, MA, USA
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The 'E' in 'Enter' should be lowercase, from what I can tell in the jQuery documentation.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •