Skip to content

Instantly share code, notes, and snippets.

@HyunsDev
Last active September 7, 2021 10:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HyunsDev/9a8dc1caab0eafbc05b6ba9114d67d3f to your computer and use it in GitHub Desktop.
Save HyunsDev/9a8dc1caab0eafbc05b6ba9114d67d3f to your computer and use it in GitHub Desktop.
['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"
})
})
@changgyu78
Copy link

이게 더 무난한것 같네요.
document.querySelectorAll('*').forEach(n=>n.style.outline = "1px solid dodgerblue");

제이쿼리가 있다면,
$("*").css("outline","1px solid dodgerblue");

@FrontLeejonghun
Copy link

꼭 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