Skip to content

Instantly share code, notes, and snippets.

@stepheneyer
Created May 1, 2015 15:48
Show Gist options
  • Save stepheneyer/659a45627b61c1af240a to your computer and use it in GitHub Desktop.
Save stepheneyer/659a45627b61c1af240a to your computer and use it in GitHub Desktop.
querySelectorAll with tags/classes
window.addEventListener("load", function (){
alert("Loaded!");
//.querySelectorAll - with tags
var listItems = document.querySelectorAll ("li");
//Becomes an array-like object, check that contains contents with .length
//listItems.length;
for (i = 0; i < listItems.length; i++) {
listItems[i].style.borderBottom = "2px solid black";
}
//.querySelectorAll - with classes
var collections = document.querySelectorAll (".datatype");
//collections.length;
for (i = 0; i < collections.length; i++) {
console.log(collections[i]);
collections[i].style.color = "red";
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment