[英]using $(this) jquery to change another element
因此,我知道如何更改懸停在同一元素上的屬性...
$(".click2play").mouseover(function()
{
$(this).css({'visibility' : 'hidden'});
});
問題我可以做同樣的事情,但只影響已懸停在同一“ click2play” div中的另一個元素嗎? 也許像?
$(".click2play").mouseover(function()
{
$(this).(#someotherdiv).css({'visibility' : 'hidden'});
});
感謝大家!
這段代碼的目標是在當前.click2play元素內的一個div。 我相信那就是您要的:)
$(".click2play").mouseover(function() {
$('div.class_name', this).css({'visibility' : 'hidden'});
});
從問題中不是很清楚你想做什么,我可以猜到所有選項
1.如果您要隱藏.click2Play
類的所有元素, .click2Play
使用
$('.click2Play').hover(function(){$('.click2play').hide()});
2.如果您只想隱藏所有具有此類使用的元素的當前元素
$('.click2Play').hover(function(){$(this).hide()});
3.如果要泛化它,則可以使用jquery對象的.selector屬性,以便像
$('.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()})});
我會這樣:
$(".click2play").mouseover(function(){
$(this).hide();
});
但這也許不是您想要的嗎?
我想這:):
$(".click2play").mouseover(function(){
$(this).css({'visibility' : 'hidden'});
});
或更好
$(".click2play").mouseover(function(){
$(this).hide();
});
您要更改其他div嗎? 為什么您需要$(this)
?
$(".click2play").mouseover(function(){
$("#someotherdiv").hide();
});
要更改單個css屬性,您可以執行以下操作:
$(".click2play").mouseover(function(){
$(this).css('visibility', 'hidden');
});
希望對您有所幫助(請考慮查看此鏈接: http : //marakana.com/bookshelf/jquery_tutorial/css_styling.html )
我相信大多數答案都沒有注意該問題,該問題詢問有關刪除班級的問題。 這是兩個問題的答案:
$('.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
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.