javascriptjqueryjquery-eventsmouseenter

Call function associated with mouseenter


With jQuery, I added a function to an element like this:

$('#theId').mouseenter(function(){
    // ...
});

Now, I want to call the function associated with #theId.mouseenter, from a script. I know this is possible:

$('#theId').mouseenter(theFunction);
function theFunction() {
    // ...
}

With this, I could call theFunction() from a script. But I'd like to know if there is a function to execute the functions associated with #theId.mouseenter. It is for example possible to run functions associated with elem.scroll by executing $(elem).scroll();. Is there something similar for the mouseenter event?


Solution

  • You can trigger mouseenter :

    $('#theId').trigger('mouseenter');
    

    http://api.jquery.com/trigger/