使用jQuery将鼠标hover在一个元素上并将效果应用于另一个元素
这是jquery:
$('.views-field').hover(function() { $('h5').css('text-decoration', 'underline'); }, function() { $('h5').css('text-decoration', 'none'); });
以上代码产生的是对所有类项的hover效果,而不仅仅是我正在hover的项。 我试着补充一下
$(this).parent('views-row').find('h5').css('text-dec', 'under')
但那里没有豆子。
你可以猜到我是一个jQuery新手,我真的很欣赏正确方向的一点……
提前致谢
尝试:
$('.views-field').hover(function() { $('h5', $(this).closest('.views-row')).css('text-decoration', 'underline'); }, function() { $('h5', $(this).closest('.views-row')).css('text-decoration', 'none'); });
您还可以使用: $(this).parents('.views-row')
附加到该特定行,但closest
只返回一个元素。
摆弄: http : //jsfiddle.net/iambriansreed/Ct39b/
试试$(this).prev().find('h5').css('text-decoration', 'underline');
如果包含h5的div总是高于.views-field
则上述情况应该有效。
$('.views-field').hover(function() { $(this).prev().find('h5').css('text-decoration', 'underline'); }, function() { $(this).prev().find('h5').css('text-decoration', 'none'); });
我认为最简单的方法是将h5
的范围扩展到前一个元素
$('.views-field').hover(function() { $('h5',$(this).prev()).css('text-decoration', 'underline'); }, function() { $('h5',$(this).prev()).css('text-decoration', 'none'); });
这是一个jsfiddle,演示: http : //jsfiddle.net/v39UQ/
请参阅此处的示例
这是代码:
$('.views-row h5').hover(function() { $(this).css('text-decoration', 'underline'); }, function() { $(this).css('text-decoration', 'none'); });
只需您的信息,您可以使用纯css为上述代码执行此操作,请参阅下面的代码:
.views-row h5:hover{ text-decoration: underline; }
Interesting Posts
$(’#foo’)。remove(’a’)和$(’#foo’)。find(’a’)。remove()之间的区别
jquery Wookmark插件Infinite Load / Scoll
为什么$(window).load()在jQuery中不起作用?
更新jquery datepicker字段后进行实时更新
在1.4中通过jquery设置选择标签
单击时在两个函数之间切换
需要Jquery代码来旋转整个div
jquery – 我可以从.ajaxStart或.ajaxStop中检索(event,xhr,options)吗?
Tab使用jQuery滑出 – 需要不止一个
如何计算jQuery中一年中的总周数?