当有许多其他具有相同类的div时,如何仅使用jquery来定位当前的hoverdiv?
如何使用jQuery hover()函数仅定位当前div(我正在盘旋)而不是所有具有相同类的div?
我的代码是这样的(我的网站上有很多div.video-item
元素(每个页面可能有所不同):
<a class="video-item-link" href="https://stackoverflow.com/questions/19140111/how-to-target-only-the-current-hovering-div-with-jquery-when-there-are-many-othe/signup"> <img class="video-item-image" src="https://stackoverflow.com/questions/19140111/how-to-target-only-the-current-hovering-div-with-jquery-when-there-are-many-othe/"> <a class="video-item-link" href="https://stackoverflow.com/questions/19140111/how-to-target-only-the-current-hovering-div-with-jquery-when-there-are-many-othe/signup"> <img class="video-item-image" src="https://stackoverflow.com/questions/19140111/how-to-target-only-the-current-hovering-div-with-jquery-when-there-are-many-othe/"> <a class="video-item-link" href="https://stackoverflow.com/questions/19140111/how-to-target-only-the-current-hovering-div-with-jquery-when-there-are-many-othe/signup"> <img class="video-item-image" src="https://stackoverflow.com/questions/19140111/how-to-target-only-the-current-hovering-div-with-jquery-when-there-are-many-othe/">
JS是:
$('a.video-item-link').hover( function() { // in $('a.video-item-link div.mouseover-element').show(); }, function() { // out $('a.video-item-link div.mouseover-element').hide(); } );
div.mouseover-element
的样式是display:none; 在默认CSS中
如何只定位鼠标结束的当前div? 现在,当我将鼠标hover在任何div.video-item-link
将显示所有25个div.mouseover
。 如何限制我当前hover的div?
使用this
,这是事件的目标,以及jQuery遍历函数:
$('a.video-item-link').hover(function() { // in $(this).find('div.mouseover').show(); }, function() { // out $(this).find('div.mouseover').hide(); } );
虽然从你的标记,看起来你需要$(this).find('div.mouseover-element')