문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 | ||
wiki:javascript:javascript_note:queryselectorall [2021/05/26 13:34] emblim98 |
wiki:javascript:javascript_note:queryselectorall [2023/01/13 18:44] (현재) |
||
---|---|---|---|
줄 315: | 줄 315: | ||
</ | </ | ||
+ | \\ | ||
+ | ====Example==== | ||
+ | 부모가 %%< | ||
+ | <code javascript> | ||
+ | < | ||
+ | < | ||
+ | div { | ||
+ | border: 1px solid #000; | ||
+ | margin-bottom: | ||
+ | } | ||
+ | </ | ||
+ | </ | ||
+ | < | ||
+ | <div> | ||
+ | < | ||
+ | <p> | ||
+ | I am a p element, my parent is a div element. <!-- teal 배경색 적용됨 --> | ||
+ | </p> | ||
+ | </ | ||
+ | <div> | ||
+ | < | ||
+ | <p> | ||
+ | I am a p element, my parent is also a div element. <!-- teal 배경색 적용됨 --> | ||
+ | </p> | ||
+ | </ | ||
+ | <p> | ||
+ | Click the button to change the background color of every p element where the parent is a div element. | ||
+ | </p> | ||
+ | |||
+ | <button onclick=" | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | function myFuncion() { | ||
+ | var x = document.querySelectorAll(" | ||
+ | var i; | ||
+ | for (i = 0; i < x.length; i++) { | ||
+ | x[i].style.backgroundColor = " | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | </ | ||
+ | |||
+ | \\ | ||
+ | ====Example==== | ||
+ | 문서에 있는 모든 %%< | ||
+ | |||
+ | <code javascript> | ||
+ | < | ||
+ | |||
+ | <h1>A H1 element</ | ||
+ | |||
+ | <h2>A H2 element</ | ||
+ | |||
+ | < | ||
+ | |||
+ | <p>A p element</ | ||
+ | |||
+ | <p>A p element with a <span style=" | ||
+ | <!-- span에 red 배경색 적용됨 --> | ||
+ | <p> | ||
+ | Click the button to set the background color of all h2, div and span elements. | ||
+ | </p> | ||
+ | |||
+ | <button onclick=" | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | function myFunction() { | ||
+ | var x = document.querySelectorAll(" | ||
+ | var i; | ||
+ | for (i = 0; i < x.length; i++) { | ||
+ | x[i].style.backgroundColor = " | ||
+ | } | ||
+ | console.log(x); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | </ | ||