Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
601 views
in Technique[技术] by (71.8m points)

jquery trigger hover on anchor

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...