單獨設置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>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM