最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Jquery only affect one element in a class being hovered - Stack Overflow

programmeradmin1浏览0评论

Not sure if this is possible. I want to select all elements with a class name and only affect the one element being hovered at that time and not the whole class. i can't use ids since they are a lot.

 $('.hideme').hover(function(){
        $('.hideme').hide();
    });

and then.

<div class='hideme'></div>

when the above hides, the following shouldn't hide.

<div class='hideme'></div>
<div class='hideme'></div>
<div class='hideme'></div>

Not sure if this is possible. I want to select all elements with a class name and only affect the one element being hovered at that time and not the whole class. i can't use ids since they are a lot.

 $('.hideme').hover(function(){
        $('.hideme').hide();
    });

and then.

<div class='hideme'></div>

when the above hides, the following shouldn't hide.

<div class='hideme'></div>
<div class='hideme'></div>
<div class='hideme'></div>
Share Improve this question asked Nov 1, 2013 at 8:29 RelmRelm 8,29520 gold badges69 silver badges114 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

If you try to hide by using clss name, then DOM will hide all the element with same name.

So you have to use this keyword for selecting current hovered element.

Try following:

$('.hideme').hover(function(){
        $(this).hide();
});
发布评论

评论列表(0)

  1. 暂无评论