How to remove css property in jQuery

前端 未结 10 1944
逝去的感伤
逝去的感伤 2020-12-04 07:48
if(prev_clicked)
{   
    $(\"#accordion li a.category\").css(\'background-image\', \'url(\"img/off_all_channel.png\")\');                    
    $(\"#accordion li          


        
相关标签:
10条回答
  • 2020-12-04 08:07

    This is literally a copy paste from this answer, and I use it to clear CSS style that I added with jQuery in a previously executed function.

    To remove the in-line CSS property use:

    $('.className').css({propertyName: ''});   
    

    To remove the whole in-line style of an element use:

    $('.className').removeAttr('style');
    

    OR by ID:

    $('#idName').removeAttr('style');
    
    0 讨论(0)
  • 2020-12-04 08:11

    I was having this problem but I have not seen any solution here that satisfies the OP. Most of the solutions suggest getting rid of the entire style attribute which is not worth it.

    I used jQuery's prop method.

    var styleObject = $('my-selector').prop('style'); 
    
    styleObject.removeProperty('background-color');
    
    0 讨论(0)
  • 2020-12-04 08:12

    Either you can set the properties back to blank:

    $(".icha0").css("background-color","");

    Or you can change the code to use classes defined in a CSS file:

    $(".icha0").addClass('properties'); 
    $(".icha0").removeClass('properties');
    
    0 讨论(0)
  • 2020-12-04 08:14

    To remove all CSS property in JQuery the following code can be use:

        $(".selector").removeClass().removeAttr('style');
    

    Thanks.

    0 讨论(0)
提交回复
热议问题