2012-05-05 50 views
0

所以,我知道如何改變你將鼠標懸停在同一元素的屬性...

$(".click2play").mouseover(function() 
      { 
       $(this).css({'visibility' : 'hidden'}); 
      }); 

問題我可以做同樣的事情,但對僅在被徘徊的相同'click2play'div內影響另一個元素? 也許像?

$(".click2play").mouseover(function() 
      { 
       $(this).(#someotherdiv).css({'visibility' : 'hidden'}); 
      }); 

謝謝大家!

+0

什麼是'$ this'? – epascarello

+0

ooops typo抱歉,並感謝 –

回答

2

這個代碼針對一個div,內當前.click2play元素。我相信這是你問的什麼:)

$(".click2play").mouseover(function() { 
    $('div.class_name', this).css({'visibility' : 'hidden'}); 
}); 
+0

謝謝!是!我想我沒有盡我所能清楚地傳達它。我會試試這個! –

+0

非常歡迎你:)對發佈的更新絕對有助於澄清事情,並請注意,您不限制使用dot_name的點運算符,還可以使用div [attr =「value」]或任何適合的您的需求! :) – Bryan

+0

感謝您的建議,可以給我一個鏈接到我可以瞭解的地方嗎? –

0

我會做這樣的:

$(".click2play").mouseover(function(){ 
    $(this).hide(); 
}); 

但也許不是你想要做什麼?

0

我想這:):

$(".click2play").mouseover(function(){ 
    $(this).css({'visibility' : 'hidden'}); 
}); 

或更好

$(".click2play").mouseover(function(){ 
     $(this).hide(); 
    }); 
0

你想改變一些其他分區?你爲什麼需要$(this)

$(".click2play").mouseover(function(){ 
    $("#someotherdiv").hide(); 
}); 
0

我相信大部分的答案沒有祈禱,關注的問題,它要求有關刪除類。下面是答案這兩個問題:

$('.click2play').bind('mouseenter mouseleave', function() { 
    $(this).removeClass('click2play'); // This line removes the current object's class click2play 
    $('jQUerySelector').removeClass('click2play'); // This will remove another element's class click2play 
}); 
1

不是很從你想對所有的選項做如此虐待答的疑問句清楚,我可以猜到的
1.如果您想隱藏.click2Play類的所有元素然後用

$('.click2Play').hover(function(){$('.click2play').hide()}); 

2.如果你只想隱藏有這類使用

$('.click2Play').hover(function(){$(this).hide()}); 

3.如果喲所有元素的當前元素ü想推廣它,那麼你可以use.selector jQuery對象的屬性,這樣你就能夠所以現在要使用它像

$('.click2Play').hover(function(){$($(this).selector).hide()}); 

,如果你將類名從.click2Play更改爲其他類它將很好地工作,並會隱藏該類的所有元素。
4.如果你想隱藏一些元素中,目前的元素,然後

$('.click2Play').hover(function(){$(this).children('selector_of_child').hide()}); 

5。如果這個類的所有元素都有一個元素在他們內部有一些其他類,並且你想隱藏它們然後簡單地使用每個像這樣的

$('.click2Play').hover(function(){$('.click2play').each(function(){$(this).children("selector_Of_Child").hide()})}); 
+0

ooh sry只需將「懸停」更改爲「mouseover」 –

相關問題