1.난수발생기
function rand(min, max){
return Math.floor(Math.random() * (max -min + 1)) + min
}
2. 콜백함수 : 함수에 파라미터에 매개변수가 들어감 => 함수실행중에 어떤 함수를 실행시키고 싶을때
function setping(func) {
console.log('먼저 처리할 일 1 => IP 유효성 체크')
console.log(' 먼저 처리할 일 2 => IP Subnet 정보 가져오기')
func()
}
function ping(){
console.log("Ping 진행중 입니다.")
}
setping(ping());
3. 색깔 랜덤
let r_color = 0
let g_color = 0
let b_color = 0
r_color = Math.floor(Math.random()* 256) => 색깔이 255개
g_color = Math.floor(Math.random()* 256)
b_color = Math.floor(Math.random()* 256)
div.style.backgroundColor = `rgb(${r_color}, ${g_color}, ${b_color})`
div.className += 'align-self-end' bootstrap 바를 아래부터 정렬
4. Dom객체 생성및 제거
const h1 = document.createElement('h1')
h1.style.color = 'tomato';
h1.textContent = '동적으로 h1 Tag만들기';
const yap = document.querySelector('.yap')
yap.appendChild(h1)
yap.removeChild(h1)
h1.parentNode.removeChild(h1)
5. 클릭한 element 삭제
const items = document.querySelectorAll("p")
for (const item of items){
item.addEventListener('click', function(){
this.remove() => this는 자기자신을 나타냄, 화살표함수에서는 this안먹는다
this.parentNode.removeChild(this)
})
}