인프런 커뮤니티 질문&답변
변수 할당
작성
·
122
0
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<div class="aa">
<h1>수요일</h1>
</div>
<script src="app.js"></script>
</body>
</html>이런 HTML파일에서 aa의 h1태그를 js로 조작하려고 합니다.
const exam = document.querySelector(".aa h1");
let example = exam.style.color;
example = "blue";
//실행 실패
// exam.style.color = "blue"; 실행 성공
console.log(example);
console.dir(exam);위의 코드처럼 exam.style.color = "blue"로는 색이 바뀌는데
exam.style.color을 변수로 잡고 실행하면 실패합니다(색이 변하지 않습니다)
example을 console.log로 찍으면 blue로 나오긴하는데 색은 변하지 않습니다
왜 이러는지 아시는 분 알려주시면 감사합니다
답변
답변을 기다리고 있는 질문이에요
첫번째 답변을 남겨보세요!




