Heojju

[javascript] document selector 본문

웹개발/JavaScript

[javascript] document selector

우주별 2017. 1. 25. 10:08


 selector

 설명

 document.getElementById

 [id]

 var elem = document.getElementById("abc");

elem.style.color="red";

 document.getElementsByName

 [name]

 var xyz= document.getElementsByName("abc");

xyz[0].style.color="red";

 document.getElementsByClassName

 [class]

 var list = document.getElementsByClassName("abc");

list[0].style.color = "red";
 document.getElementsBytagName

 [tag]

 var list = document.getElementsBytagName("p");

list[0].style.color = "red";
 document.querySelectorAll

 [*]

 var xx = document.querySelectorAll("span.a, span.c");

for (var i = 0; i < xx.length; i++) {
    xx[i].style.color="red";
}