Jquery 选择div中的所有标记
我有下面的标签结构。这在页面上重复了9次。我希望当我把鼠标悬停在9个'itemInfo'div上时,它会将所有文本颜色更改为白色(包括链接)。如何使用jQuery选择所有这些?请参阅下面我的尝试Jquery 选择div中的所有标记,jquery,jquery-selectors,Jquery,Jquery Selectors,我有下面的标签结构。这在页面上重复了9次。我希望当我把鼠标悬停在9个'itemInfo'div上时,它会将所有文本颜色更改为白色(包括链接)。如何使用jQuery选择所有这些?请参阅下面我的尝试 <div class="row itemInfo"> <div class="row"> <div class="twelve columns itemImage"> <img src="http://loremp
<div class="row itemInfo">
<div class="row">
<div class="twelve columns itemImage">
<img src="http://lorempixel.com/250/185/abstract/">
</div>
</div>
</div>
<div class="row">
<div class="twelve columns itemDetails">
<h3><a href="#">title</a></h3>
<p class="quiet">submitted by <a href="#">designer</a></p>
</div>
</div>
</div>
您可以使用通用选择器执行以下操作:
$(".itemInfo").hover(function() {
$(this).find('*').addClass('itemInfoActive');
});
查看此工作演示或使用
mouseout
或mouseover
=>
如果你想读更多:
Rest应该能满足您的需要:)
代码
$(function() {
$(".itemInfo").hover(function() {
$(this).parent().find('*').css('color', 'red');
});
});
额外代码
$(function() {
$(".itemInfo").mouseover(function() {
$(this).parent().find('*').css('color', 'red');
}).mouseout(function() {
$(this).parent().find('*').css('color', 'black');
});
});
为什么你所拥有的东西不适合你呢?你缺少了一个
})代码>在您的悬停
功能结束时…哟,布鲁夫,您缺少了.parent
:)
$(function() {
$(".itemInfo").hover(function() {
$(this).parent().find('*').css('color', 'red');
});
});
$(function() {
$(".itemInfo").mouseover(function() {
$(this).parent().find('*').css('color', 'red');
}).mouseout(function() {
$(this).parent().find('*').css('color', 'black');
});
});