简体   繁体   English

在 jQuery 中修改 CSS 类

[英]Css class modify in jQuery

I have this CSS class:我有这个 CSS 类:

    .tooltip:hover > b {
        opacity: 1;
        visibility: visible;
        display: inline;
        margin-top:30px;
    }

Now, I need to change the display to none using jQuery.现在,我需要使用 jQuery 将显示更改为无。 I tried我试过

     $('.tooltip').find('b').css('display', 'none');

and

     $('.tooltip').hover(function(){
        $(this).css('display', 'none');
     });

but niether are changing the display to none.但两者都没有将显示更改为无。 How can I achieve this?我怎样才能做到这一点?

$('.tooltip').hover(function(){
        $(this).find('b').css('display', 'none');
     });

Try this尝试这个

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

You don't need to mess with display , nor do you need to do two-steps selection: one selector is enough.您不需要弄乱display ,也不需要进行两步选择:一个选择器就足够了。

Simply do:简单地做:

$('.tooltip b').hide();

Here the reason: .css('display', 'none');原因在这里: .css('display', 'none');

use .css({'display' : 'none'});使用.css({'display' : 'none'}); make sure it is colon ":" but not a comma "," and they are inside curly braces.确保它是冒号“:”而不是逗号“,”,并且它们在花括号内。

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

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