简体   繁体   English

链接没有出现在使用jquery悬停

[英]link not appearing on hover using jquery

I want to make a div visible when hovering another div. 我想在悬停另一个div时使div可见。 Now, I know this can be implemented using simply jquery but its not working. 现在,我知道这可以使用简单的jquery实现,但它不起作用。 I am populating a list using javascript as given below : 我使用javascript填充列表,如下所示:

function coachingLink(data, list) {
   list = list
    + '<div class="**coachingLinkDisplay**"><p class="coachingLink" align="left" style="color:#CD3700;">'
    + data.coachingName
    + '</p><br/>'
    + '<p class="title" style="color:black;font-size:14pt;">Subjects : '
    + subjects + '</p><br/><p class="content" align="left"></b>'
    + data.description + '</p></div></a><a href="batch.html?coachingId='
    + data.coachingId
    + '" class="**batchButton**"><b>View Batches</b></a>';

    return list;
}

Now what I want that when hovering over coachingLinkDisplay, batchButton should appear (whose display is none initially) . 现在我想要的是当悬停在coachingLinkDisplay上时,应该出现batchButton(最初显示为none)。 So I wrote the code : 所以我写了代码:

$(document).ready(
   function() {
     $('.coachingLinkDisplay').hover(function() {
     $('.batchButton').css('display', 'block');
   }); 
});

But the code is not working. 但是代码不起作用。 It seems as the list is being populated using JS, may be the above jquery snippet is failing as I have tried the snippet for normal div and is working properly. 看起来正在使用JS填充列表,可能是上面的jquery片段失败,因为我已经尝试了正常div的片段并且正常工作。 So, I tried to use css approach as I read in various blogs: 所以,我尝试使用css方法,因为我在各种博客中阅读:

.coachingLinkDisplay:hover  + .batchButton{
   display:block;
}

But again no luck..is there any problem in above css code? 但又没有运气..上面的css代码有什么问题吗? Please help me out here...how to implement my requirement...? 请帮帮我......如何实现我的要求......?

You need to delegate the hover function. 您需要委派悬停功能。 This is because the event handler is only bound to elements available during document ready. 这是因为事件处理程序仅绑定到文档就绪期间可用的元素。

$(document).on('mouseover', '.coachingLinkDisplay', function(){
    $('.batchButton').css('display', 'block');
});

Replace document with the closest static parent element. 用最接近的静态父元素替换document

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM