How to reload or rerender CSS for a single HTML element?

This question already has an answer here:

  • How can I remove a style added with .css() function? 16 answers

  • With jQuery, you are adding your styles to the style attribute of the element. It is removed again, if you call the function again with an empty string ( "" ). This will remove the property in the style attribute.

    If you have eg this command:

    $('.foo').css('height', '100px');
    

    You can revoke it by

    $('.foo').css('height', '');
    

    See also the discussion here: https://stackoverflow.com/a/4036868/3233827


    $('.foo).height(''); should be sufficient to erase the style applied by jQuery


    You can remove the style attribute from the element. This attribute holds any dynamic styles.

    $('.foo').css('background', 'teal');
    
    $('#reset').click(function() {
        $('.foo').removeAttr('style');
    });
    .foo {
        height:100px;
        width:100px;
        background:red;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
    
    <div class="foo"></div>
    <p><button id="reset">Reset style</button></p>
    链接地址: http://www.djcxy.com/p/94868.html

    上一篇: 如何删除样式属性

    下一篇: 如何重新加载或重新渲染单个HTML元素的CSS?