if(prev_clicked)
{   
    $("#accordion li a.category").css('background-image', 'url("img/off_all_channel.png")');                    
    $("#accordion li a.comment").css('background-image', 'url("img/on_all_online.png")');                   
    $(".icha0").removeProperty("background-color");
    $(".icha0").removeProperty("opacity");
}
else
{   
   $(".icha0").css("background-color","#D5D5D2");
   $(".icha0").css("opacity","0.70");
}

我试图删除我添加的两个css属性,但似乎不工作。 尽管吗?


当前回答

我们有两种方法,要么你可以直接删除应用到DOM元素的CSS样式类,要么从元素中删除应用的CSS样式

//Remove the class associated with element

$('#ID').removeClass("cssClass");

//Remove the CSS style from DOM element

$('p').css({"color":""});

其他回答

你可以设置属性为空:

$(“.icha0”).css(“background-color”,“”);

或者您可以更改代码使用CSS文件中定义的类:

$(".icha0").addClass('properties'); 
$(".icha0").removeClass('properties');

与jquery

  $('#ID').removeAttr("style")

withoyt jquery

document.getElementById("ID").removeAttribute("style")

如果你需要删除而不是更新一个特定的属性,你可以简单地使用removeProp而不是removeProperty:

$(".icha0").removeProp("background-color");
$(".icha0").removeProp("opacity");

我有这个问题,但我没有看到任何解决方案,在这里满足op。大多数解决方案建议摆脱整个风格属性,这是不值得的。

我使用jQuery的道具方法。

var styleObject = $('my-selector').prop('style'); 

styleObject.removeProperty('background-color');
<script>
        require(['jquery', 'domReady!'], function($) {
            if ($('#p_method_use_reward_points').prop('checked')) {
                $('.test').show();
                console.log('working');
            }else{
                $('.test').hide();
                console.log('not working');
            }
            $('#submit_reward').on('click', function (e){
                let getPoints = $('#custom_reward_set').val();
                let checkField = $('#custom_reward_set').prop("readonly");
                // alert(getPoints);
                if (!getPoints){
                    alert('PLease add reward points');
                }
                if (getPoints) {
                    $("#custom_reward_set").prop("readonly", !$("#custom_reward_set").attr('readonly'));
                    if ($('#custom_reward_set').is('[readonly]')) {
                        $("#custom_reward_set").css({
                            "background-color": "#EBEBE4",
                            "border": "1px solid #ABADB3", "cursor": "not-allowed"
                        });
                    }else{
                        $('#custom_reward_set').removeAttr('style');
                    }
                }
               e.preventDefault();

            })
        });
    </script>