add :hover selector to class 1 when hovering over class 2

為{幸葍}努か 提交于 2019-12-11 02:36:39

问题


I'm trying to add the :hover selector to a class when hovering over a different div. Basically there are 2 divs forming a button. The top part is the part that changes color when hovered over and the bottom part is simply an image. Currently, the hover only works for the top part, but I want the :hover selector to be called when hovering over the image too.

Basically it doesn't function as a single button but rather two buttons.

This is what I have but obviously this doesn't work.

$(".module-feature-img").hover(function(){
   $(".module-title-bottom").attr('class', '.module-title-bottom:hover') 
});

Also, I noticed that it stays stuck like that after I move my mouse away.

Help would be greatly appreciated


EDIT

Functioning site: www.exo-l.com

It's about the buttons on the bottom

I also realized this is not really going to work because there are 4 buttons and they all have the same class.. so if I hover over 1 image, they all would get the :hover selector. Any ideas?


回答1:


you can use this: http://jsfiddle.net/ZTU5v/

$(".module-feature-img").hover(function(){
  $(".module-title-bottom").addClass('hover');
}, function(){
  $(".module-title-bottom").removeClass('hover');
});​

add a callback function to remove the class.




回答2:


$(".module-feature-img").hover(function(){
   $(".module-title-bottom").trigger('hover'); 
});



回答3:


I'd add a .hover class and apply to it the same rule as for :hover in your CSS.



来源:https://stackoverflow.com/questions/14013958/add-hover-selector-to-class-1-when-hovering-over-class-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!