How to apply !important using .css()?

后端 未结 30 3042
情深已故
情深已故 2020-11-21 07:06

I am having trouble applying a style that is !important. I’ve tried:

$(\"#elem\").css(\"width\", \"100px          


        
30条回答
  •  一整个雨季
    2020-11-21 07:22

    Three working examples

    I had a similar situation, but I used .find() after struggling with .closest() for a long time with many variations.

    The Example Code

    // Allows contain functions to work, ignores case sensitivity
    
    jQuery.expr[':'].contains = function(obj, index, meta, stack) {
        result = false;
        theList = meta[3].split("','");
        var contents = (obj.textContent || obj.innerText || jQuery(obj).text() || '')
        for (x=0; x= 0) {
                return true;
            }
        }
        return false;
    };
    
    $(document).ready(function() {
        var refreshId = setInterval( function() {
            $("#out:contains('foo', 'test456')").find(".inner").css('width', '50px', 'important');
        }, 1000); // Rescans every 1000 ms
    });
    

    Alternative

    $('.inner').each(function () {
        this.style.setProperty('height', '50px', 'important');
    });
    
    $('#out').find('.inner').css({ 'height': '50px'});
    

    Working: http://jsfiddle.net/fx4mbp6c/

提交回复
热议问题