32

I'm using jQuery to develop in web environment.

I want to know why

 $("#a#trigger").trigger('mouseenter');
 $("#a#trigger").trigger('hover');
 $("#a#trigger").trigger('mouseover');

All 3 of those aren't working to activate a hover function that I have.

$(function() {


        $('a#trigger').hover(function(e) {
          $('div#pop-up').show();

             }, function() {
          $('div#pop-up').hide();
        });

     });

      });

a#trigger is the name of the anchor, and #pop-up is a div element in my web.

The problem is that I want to mouse over some event in FullCalendar plugin and those functions aren't working. Thanks.

seanbreeden
  • 6,104
  • 5
  • 36
  • 45
Ori Refael
  • 2,888
  • 3
  • 37
  • 68

2 Answers2

84

You are on the right track, the problem is the extra # in the selector, just remove the first hash:

$("a#trigger").trigger('mouseenter');

Note that since IDs must be unique, there is no need to specify the element type, $('#trigger') is more efficient.

Also note that:

Deprecated in jQuery 1.8, removed in 1.9: The name "hover" used as a shorthand for the string "mouseenter mouseleave". It attaches a single event handler for those two events, and the handler must examine event.type to determine whether the event is mouseenter or mouseleave. Do not confuse the "hover" pseudo-event-name with the .hover() method, which accepts one or two functions.

Ram
  • 143,282
  • 16
  • 168
  • 197
  • 6
    wow im blind like hell after 25 hours of programming, thank you very much. and its was Mouseenter by the way..hover not working @undefined – Ori Refael Jun 17 '12 at 21:18
  • 1
    I don't know why I failed using `trigger(mouseenter)` somehow, but end up success by writing a `.hover` class and do `addClass('hover')`. – Liber Jul 20 '15 at 06:05
10

Your jQuery selector should be written as e.g.

$('a#trigger');

instead of $('#a#trigger');

In jQuery a # in a selector matches an id. In this case trigger is an id, but a is an HTML element and requires no prefix.

Your final code would be:

$("a#trigger").trigger('mouseenter');
$("a#trigger").trigger('hover');
$("a#trigger").trigger('mouseover');
Jonathan Nicol
  • 3,158
  • 1
  • 21
  • 22