单独设置css的class属性

 

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>单独设置css的class属性</title>
    <style>
        .error{
            width: 100px;
            height: 100px;
            color: red !important;
        }
    </style>
</head>
<body>

<div class="error" id="div1" style="background:black;color:blue;">hello world</div>
<script>
    var odiv = document.getElementById('div1');

    //设置单个属性
//    odiv.style.setProperty('color', 'green', 'important');
    
    //设置整个style属性
//    odiv.setAttribute('style', 'color:green !important');


    //http://stackoverflow.com/questions/19828515/how-to-override-css-containing-important-using-jquery
</script>
</body>
</html>

 

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>单独设置cssclass属性</title>
<style>
.error{
width:100px;
height:100px;
color:red !important;
}
</style>
</head>
<body>

<div class="error" id="div1" style="background:black;color:blue;">helloworld</div>
<script>
var odiv = document.getElementById('div1');

//设置单个属性
// odiv.style.setProperty('color', 'green', 'important');

//设置整个style属性
// odiv.setAttribute('style', 'color:green !important');


//http://stackoverflow.com/questions/19828515/how-to-override-css-containing-important-using-jquery
</script>
</body>
</html>
posted @ 2016-04-08 16:22  马斯塔  阅读(3534)  评论(0编辑  收藏  举报