这是样本结构!如何在jquery中选择一个孩子?
<div id ="div1">
<div class="div1-child">
<div class="div1-sub-child">
</div>
</div>
</div>
任何人都可以帮助我如何应用div1子子jQuery效果当我悬停div1?
这是样本结构!如何在jquery中选择一个孩子?
<div id ="div1">
<div class="div1-child">
<div class="div1-sub-child">
</div>
</div>
</div>
任何人都可以帮助我如何应用div1子子jQuery效果当我悬停div1?
你不jQuery这样做。使用只是CSS你得到它的工作。如下 -
#div1:hover .div1-sub-child {
background-color:yellow
}
使用jQuery -
$('#div1').hover({function(){ //this is called whn mouse enters the div
$(this).find('.div1-sub-child').css('background-color','red'); //your effect here
},function(){ //this is called whn mouse leaves the div
$(this).find('.div1-sub-child').css('background-color','green'); //your effect here
})
也许像
$(".div1-child").hover(
function() {
$(this).find('.div1-sub-child').css(*** your new css ***);
});
你的函数将选择所有具有div-sub-child类的元素,而不管它们在DOM中的位置。使用'$(this).find(selector)'使其相对于'this' – 2013-02-20 12:20:59
感谢符文FS,请参阅编辑:) – alemangui 2013-02-20 12:26:03
尝试
$("#div1").hover(
function()
{
$(this).find('div.div1-sub-child').filter(':not(:animated)').animate(
{
marginLeft:'9px'
},'slow');
},
function()
{
$(this).find('div.div1-sub-child').animate(
{
marginLeft:'0px'
},'slow');
});
哈弗有两个callbacks
一会火的时候,你hover
和hoverOut
。
谢谢你们帮助我 – 2013-02-20 20:07:13
使用jQuery
$('#div1').hover({function(){ //this is called whn mouse enters the div
$(this).find('.div1-sub-child').css('background-color','red'); //your effect here
},function(){ //this is called whn mouse leaves the div
$(this).find('.div1-sub-child').css('background-color','green'); //your effect here
})
添加特殊样式的div尝试:
$("#div1").hover(
function() {
$(this).find('div.div1-sub-child').addClass("hover");
},
function() {
$(this).find('div.div1-sub-child').removeClass("hover");
}
);
这是很多时候,当你使用jQuery和PHP的工作。而且也有办法很多对在这里做我要添加其中的一个。希望这可以帮助你。 ('#div1 .div1-child')。children()。addClass('addclass');
谢谢你们帮助我...... – 2013-02-20 20:00:01