显示无!使用 jQuery 覆盖的重要需求

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18784593/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 22:31:27  来源:igfitidea点击:

Display none ! important need to override by using jQuery

jquerycss

提问by Sampath

Anyone who is knowing how to override the below mentioned css by using jQuery ?

任何知道如何使用 jQuery 覆盖下面提到的 css 的人?

 .actionButton.single-pet
        {
            display: none !important;
        }

It won't work for this : $('.actionButton.single-pet').show();

它不会为此工作: $('.actionButton.single-pet').show();

回答by wei2912

$('.actionButton.single-pet').attr("style", "display: inline !important");

Sets CSS to display: inline !important;. display: inlineis the default property for display. You need !importantagain to override the previous !important.

将 CSS 设置为display: inline !important;. display: inline是 的默认属性display。您需要!important再次覆盖之前的!important.

Note that !importantshouldn't be used often. Read the accepted answer at How to override !important?for more details.

请注意,!important不应经常使用。阅读How to override !important? 中已接受的答案更多细节。

UPDATE: We can't use .css()here as it does not support !important. http://bugs.jquery.com/ticket/11173for more details; appears to be a bug.

更新:我们不能.css()在这里使用,因为它不支持!important. http://bugs.jquery.com/ticket/11173了解更多详情;似乎是一个错误。

回答by A. Wolff

$('.actionButton.single-pet').removeClass('single-pet');

Or just:

要不就:

$('.actionButton.single-pet').addClass('single-pet-shown');

With CSS:

使用 CSS:

.actionButton.single-pet-shown {
    display: block !important;
}