깃허브 : https://github.com/cheryea/personal-study/issues?q=is%3Aopen+is%3Aissue+label%3AJavaScript
변수
var ul=document.querySelectorAll('.ul');
document.getElementById(' ').classList.toggle(' ');
스타일 속성 변경
document.getElementById(" ").style.display = " ";
클래스 주기
document.getElementById(" ").className = " ";
클래스 빼기
변수.classList.remove(' ');
클래스 주기 ( 클래스 여러개 주기 가능 )
변수.this.classList.add(' ');
// 스크롤이 650 일 때
window.onscroll = function() {
if (window.pageYOffset < 650)
}
// 스크롤이 최상단 일 때
window.onscroll = function(){
var scrollPosition = window.scrollY || document.documentElement.scrollTop;
if(scrollPosition == 0){
}
}
// 스크롤 top 가기
document.body.scrollTop = document.documentElement.scrollTop = 0;
// 외부 클릭시 div 사라지기
document.addEventListener('mouseup', function(e) {
var container = document.getElementById(' ');
if (!container.contains(e.target)) {
}
});
// 여러 요소 선택
var ul = document.querySelectorAll('.ul');
ul[0].addEventListener('click',function(){ document.getElementById("inul1").style.display = "block";
});
ul[1].addEventListener('click',function(){ document.getElementById("inul2").style.display = "block";
});
// if문으로 홀수 , 짝수 구하기
if(num % 2 === 1){
return '홀수';
} else {
return '짝수';
}
if(num % 2 === 0){
return '짝수';
} else {
return '홀수';
}