문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 양쪽 이전 판 이전 판 다음 판 | 이전 판 | ||
|
wiki:javascript:javascript_note:queryselector [2021/05/26 08:58] emblim98 |
wiki:javascript:javascript_note:queryselector [2023/01/13 18:44] (현재) |
||
|---|---|---|---|
| 줄 50: | 줄 50: | ||
| ====Example==== | ====Example==== | ||
| <code javascript> | <code javascript> | ||
| + | < | ||
| + | < | ||
| + | |||
| + | < | ||
| + | |||
| + | < | ||
| + | |||
| + | <button onclick=" | ||
| + | |||
| + | < | ||
| + | function myFunction() { | ||
| + | document.querySelector(" | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | </ | ||
| </ | </ | ||
| + | ====Example==== | ||
| + | 문서에서 %%class=" | ||
| + | <code javascript> | ||
| + | < | ||
| + | <h2 class=" | ||
| + | <p class=" | ||
| + | <!-- crimson backgroundColor 적용 --> | ||
| + | <p> | ||
| + | Click the button to add a background color to the first p element | ||
| + | in the document with class=" | ||
| + | </p> | ||
| + | <button onclick=" | ||
| + | < | ||
| + | function myFunction() { | ||
| + | document.querySelector(" | ||
| + | } | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ====Example==== | ||
| + | %%id=" | ||
| + | <code javascript> | ||
| + | < | ||
| + | |||
| + | <p id=" | ||
| + | <!-- Hello World!로 텍스트가 변경됩니다. --> | ||
| + | |||
| + | < | ||
| + | |||
| + | <button onclick=" | ||
| + | |||
| + | < | ||
| + | function myFunction() { | ||
| + | document.querySelector("# | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ====Example==== | ||
| + | %%< | ||
| + | <code javascript> | ||
| + | < | ||
| + | < | ||
| + | div { | ||
| + | border: 1px solid #000; | ||
| + | } | ||
| + | </ | ||
| + | </ | ||
| + | < | ||
| + | |||
| + | <div> | ||
| + | < | ||
| + | <p>I am a p element, my parent is a div element.</ | ||
| + | // green background color가 적용됩니다. | ||
| + | </ | ||
| + | |||
| + | <div> | ||
| + | < | ||
| + | <p>I am a p element, my parent is also a div element.</ | ||
| + | </ | ||
| + | |||
| + | <p> | ||
| + | Click the button to change the bacgkround color of the first p element | ||
| + | in the document where the parent is a div element. | ||
| + | </p> | ||
| + | |||
| + | <button onclick=" | ||
| + | |||
| + | < | ||
| + | function myFunction() { | ||
| + | var x = document.querySelector(" | ||
| + | x.style.backgroundColor = " | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ====Example==== | ||
| + | 문서에서 %%" | ||
| + | <code javascript> | ||
| + | < | ||
| + | < | ||
| + | a[target] { | ||
| + | background-color: | ||
| + | } | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | |||
| + | <p> | ||
| + | The CSS selector a[target] makes sure that | ||
| + | all links with a target attribute gets a yellow background: | ||
| + | </p> | ||
| + | |||
| + | <a href=" | ||
| + | <a href=" | ||
| + | <a href=" | ||
| + | |||
| + | <p> | ||
| + | Click the button to add a red border to the first link that has a target attribute. | ||
| + | </p> | ||
| + | |||
| + | <button onclick=" | ||
| + | |||
| + | < | ||
| + | function myFunction() { | ||
| + | document.querySelector(" | ||
| + | } | ||
| + | </ | ||
| + | | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ====Example==== | ||
| + | 다음 예제는 여러 선택자가 작동하는 방식을 보여줍니다.\\ | ||
| + | \\ | ||
| + | 두 개의 요소, 즉 %%< | ||
| + | \\ | ||
| + | 다음 코드는 문서의 첫 번째 %%< | ||
| + | \\ | ||
| + | <code javascript> | ||
| + | < | ||
| + | |||
| + | <h2>A h2 element</ | ||
| + | <h3>A h3 element</ | ||
| + | |||
| + | < | ||
| + | document.querySelector(" | ||
| + | </ | ||
| + | | ||
| + | </ | ||
| + | </ | ||
| + | \\ | ||
| + | 그러나 %%< | ||
| + | %%< | ||
| + | \\ | ||
| + | <code javascript> | ||
| + | < | ||
| + | |||
| + | <h3>A h3 element</ | ||
| + | <h2>A h2 element</ | ||
| + | |||
| + | < | ||
| + | document.querySelector(" | ||
| + | </ | ||
| + | |||
| + | </ | ||
| + | </ | ||
| {{tag> | {{tag> | ||