본문 바로가기

JavaScript/javascript 기초 공부하기

javascript로 css 조작하기

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
</head>

<body>
    <div id="demo">Hello CSS World</div>
    <br>
    <button onclick="func()">적용</button>

    <script>
        function func() {
            obj = document.getElementById("demo");
            obj.style.color = "white";
            obj.style.backgroundColor = "blue";
            obj.style.textAlign = "center";
            obj.style.borderStyle = "double";
            obj.style.borderColor = "red";
            obj.style.fontFamily = "MS PGothic";
            obj.style.fontStyle = "italic";
            obj.style.fontSize = "24pt";
        }
    </script>
</body>

</html>