這是樣本結構!如何在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