Last active
September 7, 2021 10:43
-
-
Save HyunsDev/9a8dc1caab0eafbc05b6ba9114d67d3f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
['div', 'span', 'ul', 'li', 'dd', 'dl', 'section', 'h1', 'a', 'img', 'form', 'button', 'header', 'footer', 'input', 'p'].forEach(e => { | |
document.querySelectorAll(e).forEach(element => { | |
element.style.outline = "1px solid dodgerblue" | |
}) | |
}) |
꼭 DOM Name을 forEach 돌릴 필요 없이 querySelectorAll에 배열을 넣어도 동일하게 작동합니다.
document.querySelectorAll(['div', 'span', 'ul', 'li', 'dd', 'dl', 'section', 'h1', 'a', 'img', 'form', 'button', 'header', 'footer', 'input', 'p']).forEach(element => { element.style.outline = "1px solid dodgerblue" })
만약 태그를 선택해야한다면 기존방법이 더 낫지만, 태그를 선택하지않고 모든것을 한다면 78님 말씀대로 가는것도 깔끔해보입니다.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
이게 더 무난한것 같네요.
document.querySelectorAll('*').forEach(n=>n.style.outline = "1px solid dodgerblue");
제이쿼리가 있다면,
$("*").css("outline","1px solid dodgerblue");