0

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

3 Answers3

2

You can trigger mouseenter :

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

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

Philippe Boissonneault
  • 3,949
  • 3
  • 26
  • 33
1

Use .trigger();

$('#theId').trigger("mouseenter");
Adil Shaikh
  • 44,509
  • 17
  • 89
  • 111
1

You actually don't need the trigger at all - just $('#theId').mouseenter();