Last active
March 1, 2017 23:55
-
-
Save wrburgess/76440aa9e06c462b8bcf9a6dbfdba3d1 to your computer and use it in GitHub Desktop.
JS snippets: for-loop, if-then-else, create-object, html-selectors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// for-loop | |
for (counter = 0; counter < array.length; counter++) { | |
// do some stuff! | |
} | |
// if-then-else | |
if (x < y) { | |
// do something | |
} else if (z === a) { | |
// do something | |
} else { | |
// do something | |
} | |
// create-object | |
var jsObject = { | |
propOne: "something", | |
propTwo: 2, | |
propThree: ["array", "array", "array"], | |
propFour: true, | |
propFive: function() { | |
// do something | |
} | |
} | |
// html-selectors | |
// ref: https://www.w3schools.com/js/js_htmldom_elements.asp | |
var something = document.getElementById("the-id-name"); | |
var something = document.getElementsByTagName("p"); | |
var something = document.getElementsByClassName("class-name"); | |
var something = document.querySelector("#id-name"); | |
var something = document.querySelector(".class-name"); | |
var something = document.querySelector("element"); | |
var something = document.querySelectorAll("p.intro"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment