How to detect mouseleave() on two elements at once?

后端 未结 5 1342
别跟我提以往
别跟我提以往 2020-12-06 11:15

Answer can be in vanilla js or jQuery. I want to hide a div with the id \"myDiv\" if the user is no longer hovering over a link with the id \"myLink\" or a span with the id

5条回答
  •  旧巷少年郎
    2020-12-06 12:18

    I think, it's your solution!!!

    $(document).ready(function() {
        var someOtherElement = "";
        $("#someElement").hover(function(){
            var someOtherElement = $(this).attr("href");
            $(someOtherElement).show();
        });
        $("#someElement").mouseleave(function(){
            var someOtherElement= $(this).attr("href");
            $(someOtherElement).mouseenter(function(){
            $(someOtherElement).show();
            });
            $(someOtherElement).mouseleave(function(){
            $(someOtherElement).hide();
            });
    
        });
    });
    
    ----
    html
    ----
    
    
    
    
    

提交回复
热议问题