Javascript Can';我不知道如何在jQuery中正确使用$(this)来获取悬停元素
所以我有几个div叫做acgression,每个div都包含一个跨度叫做recentshare。我想做的是首先隐藏每个最近的共享,并在父类“acheivement”悬停时显示它。我正在尝试使用$(这个)来获得它,但它不起作用。我假设这是一个语法错误或什么的,任何帮助将不胜感激Javascript Can';我不知道如何在jQuery中正确使用$(this)来获取悬停元素,javascript,jquery,hover,this,show,Javascript,Jquery,Hover,This,Show,所以我有几个div叫做acgression,每个div都包含一个跨度叫做recentshare。我想做的是首先隐藏每个最近的共享,并在父类“acheivement”悬停时显示它。我正在尝试使用$(这个)来获得它,但它不起作用。我假设这是一个语法错误或什么的,任何帮助将不胜感激 <script> $(".recent-share").hide(); $('.achievement').hover( function ()) { $
<script>
$(".recent-share").hide();
$('.achievement').hover(
function ()) {
$(this).next(".recent-share").show();
});
</script>
$(“.recent share”).hide();
$('.Achasition')。悬停(
函数()){
$(this).next(“.recentshare”).show();
});
试试:
您还有一个语法错误–应该是function(){
,而不是function(){
请尝试:
您还有一个语法错误–它应该是function(){
,而不是function(){
。next()
以兄弟姐妹为目标。请尝试:
<script>
$(".recent-share").hide();
$('.achievement').hover(
function ()) {
$(this).find(".recent-share").show();
});
</script>
$(“.recent share”).hide();
$('.Achasition')。悬停(
函数()){
$(this.find(“.recentshare”).show();
});
.next()
以兄弟姐妹为目标。请尝试:
<script>
$(".recent-share").hide();
$('.achievement').hover(
function ()) {
$(this).find(".recent-share").show();
});
</script>
$(“.recent share”).hide();
$('.Achasition')。悬停(
函数()){
$(this.find(“.recentshare”).show();
});
可以尝试以下三种方法之一:
1.子项()查找
$(this).children('.recent-share')
$('> .recent-share',this)
$(this).find('> .recent-share') // is basically the same as nº2
2.上下文查找
$(this).children('.recent-share')
$('> .recent-share',this)
$(this).find('> .recent-share') // is basically the same as nº2
3.find()
$(this).children('.recent-share')
$('> .recent-share',this)
$(this).find('> .recent-share') // is basically the same as nº2
未测试,在我的代码片段中有此功能。可以尝试以下三种方法之一: 1.子项()查找
$(this).children('.recent-share')
$('> .recent-share',this)
$(this).find('> .recent-share') // is basically the same as nº2
2.上下文查找
$(this).children('.recent-share')
$('> .recent-share',this)
$(this).find('> .recent-share') // is basically the same as nº2
3.find()
$(this).children('.recent-share')
$('> .recent-share',this)
$(this).find('> .recent-share') // is basically the same as nº2
没有测试,在我的代码片段中有这个