1. document.getElementById();
2. document.getElementsByClassName();
3. document.querySelector();
const a = document.getElementById();
a.addEventListener("event", "function")
const a = document.getElementById();
function changeColor(){
a.style.color = "blue";
}
a.addEventListener("click", changeColor);
#style.css
.active {
color : blue;
}
#app.js
const a = document.getElementById();
function changeClassName(){
a.className = "active";
}
a.addEventListener("click", changeClassName);
#style.css
.active {
color : blue;
}
#app.js
const a = document.getElementById();
function changeClassName(){
a.classList.add("active");
}
a.addEventListener("click", changeClassName);
const a = document.getElementById();
function changeColor(){
const changedState = "active";
if(a.classList.contains(changedState)){
a.classList.remove(changedState);
} else{
a.classList.add(changedState);
}
}
a.addEventListener("click", changeColor)
const a = document.getElementById();
function changeColor(){
a.classList.toggle('active')
}
a.addEventListener("click", changeColor)
결론 : 토글은 신이다..