Can I use jquery to remove/negate css !important rule?

后端 未结 5 1401
挽巷
挽巷 2020-12-16 12:07

If there is a CSS rule that uses !important, is there a way to remove the !important rule so that I can make further downstream style changes with

5条回答
  •  情书的邮戳
    2020-12-16 12:08

    you can add a new css style with the !important added to it that will override the original style

    This is from another answer in javascript:

    function addNewStyle(newStyle) {
    var styleElement = document.getElementById('styles_js');
    if (!styleElement) {
        styleElement = document.createElement('style');
        styleElement.type = 'text/css';
        styleElement.id = 'styles_js';
        document.getElementsByTagName('head')[0].appendChild(styleElement);
    }
    styleElement.appendChild(document.createTextNode(newStyle));
    }
    
     addNewStyle('td.EvenRow a {display:inline !important;}')
    

    this answer is here

    Also I believe that you can add styling like this

            .css({ 'display' : 'block !important' });
    

    in jQuery

提交回复
热议问题