将鼠标悬停在另一个类上时将类添加到一个div(Javascript) [英] add class to a div when hover another one (Javascript)

查看:91
本文介绍了将鼠标悬停在另一个类上时将类添加到一个div(Javascript)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Javascript的理解有限我想将一个类添加到div,当我悬停另一个div
现在我可以添加一个类到同一个div但我希望能够添加let's当我将#second和#third悬停时,将班级蓝色称为第一个div。



现在的代码:

 

$(document).ready(function(){
$(#second,#third)。hover(function(){
$(this).addClass(hover);
$(this).removeClass(hoverable);
},
function(){
$(this).removeClass(hover);
$(这个).addClass(hoverable);
}
);
});

我的网站可以在www.designinterieurm2.com/dev

解决方案

$(document).ready(function(){
$(' ()函数(){$ b $('#first')。addClass('blue');
},
函数(){$ b $ ($'$')。


I have a limited understanding of Javascriptan I am trying to add a class to a div when I hover another div Right now I can add a class to the same div but I would like to be able to add let's say the class blue to a div called first when I hover #second and #third.

current code :

    
    $(document).ready(function() {     
    $("#second, #third").hover(function(){     
    $(this).addClass("hover");    
    $(this).removeClass("hoverable");      
    },     
    function(){    
    $(this).removeClass("hover");     
        $(this).addClass("hoverable");     
    }  
    );     
    });        

My live website can be seen at : www.designinterieurm2.com/dev

解决方案

$(document).ready(function() {     
    $('#second, #third').hover(function(){     
        $('#first').addClass('blue');    
    },     
    function(){    
        $('#first').removeClass('blue');     
    });
});   

这篇关于将鼠标悬停在另一个类上时将类添加到一个div(Javascript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆