我有以下设置:当父徘徊格,改变孩子的背景颜色的div
<div class="parent">
<div class="child">
</div>
<div class="child">
</div>
<div class="child">
</div>
</div>
我试图改变所有这些的所有背景色在同一时间,当鼠标盘旋在其中任何一个。我想:
<script type="text/javascript">
$(function() {
$('.parent').hover(function(){
$(this).css('background-color', 'gray');
},
function(){
$(this).css('background-color', 'red');
});
});
</script>
但是,孩子们<div>
S上的颜色是不是 “通过展示”。
有没有办法选择“this”的后代。我有很多这样的组合,因此我认为我需要使用“this”,所以我没有通过id调用每个父组件。我想是这样的:
<script type="text/javascript">
$(function() {
$('.parent').hover(function(){
$(this "div").css('background-color', 'gray');
},
function(){
$(this "div").css('background-color', 'red');
});
});
</script>
但是,不能完全得到它的工作 - 都在jquery.com的例子使用的ID选择......没有用“本”。
非常感谢!
也许t他就是你要找的东西:http://api.jquery.com/children/。 – pimvdb 2011-02-27 19:59:00