jQuery - Display an element on hover of another

后端 未结 2 1349
醉梦人生
醉梦人生 2021-01-26 07:14

This could be done easily in CSS if the element that needs to be displayed was a child of the hover, but it isn\'t; it\'s in a different section of the document.

I\'m t

2条回答
  •  北海茫月
    2021-01-26 08:12

    Here is a simple example where you hover over one element and a completely different element is changed,

    http://jsfiddle.net/bUqKq/6/

    hover here
    hover here2

     

    $("#one").on("mouseover",function(){
        $("#two").css({
            color:"red"
        })
    });
    
    $("#one").on("mouseout",function(){
        $("#two").css({
            color:"black"
        })
    });
    
    $("#two").on("mouseover",function(){
        $("#one").css({
            color:"red"
        })
    });
    
    
    $("#two").on("mouseout",function(){
        $("#one").css({
            color:"black"
        })
    });
    

提交回复
热议问题