悬停在另一个div上时将类添加到div(Javascript)

悬停在另一个div上时将类添加到div(Javascript),javascript,jquery,html,css,Javascript,Jquery,Html,Css,我对Javascriptan的理解有限,当我悬停在另一个div上时,我正试图向一个div添加一个类 现在,我可以将一个类添加到同一个div中,但我希望能够在悬停#second和#third时将类blue添加到名为first的div中 当前代码: $(document).ready(function() { $("#second, #third").hover(function(){ $(this).addClass("hover");

我对Javascriptan的理解有限,当我悬停在另一个div上时,我正试图向一个div添加一个类 现在,我可以将一个类添加到同一个div中,但我希望能够在悬停#second和#third时将类blue添加到名为first的div中

当前代码:

    
    $(document).ready(function() {     
    $("#second, #third").hover(function(){     
    $(this).addClass("hover");    
    $(this).removeClass("hoverable");      
    },     
    function(){    
    $(this).removeClass("hover");     
        $(this).addClass("hoverable");     
    }  
    );     
    });        
我的实时网站可在以下网址查看:www.designinterieurm2.com/dev

只需将
$(此)
替换为
$(“#div_id”)


其中
#div_id
是您试图更改的div的id。

这可能包括某种类型的DOM遍历,相关的html是什么样子的?谢谢它成功了!我犯的错误是在函数中使用双引号而不是单引号不,对不起,这不是问题所在。双引号或单引号都可以,只要整体语法正确,就可以使用其中一种。事实上,我更喜欢单引号,当我注意到它们时,会消除双引号。
$(document).ready(function() {     
    $('#second, #third').hover(function(){     
        $('#first').addClass('blue');    
    },     
    function(){    
        $('#first').removeClass('blue');     
    });
});   
$(".toptab").hover(function(){

    $(this).addClass("current");
    $(this).find("ul").show();

},function(){

    $(this).find("ul").hide();
    $(this).removeClass("current");

});