Created
May 13, 2012 23:59
-
-
Save jahfer/2690856 to your computer and use it in GitHub Desktop.
JavaScript: Hints
This file contains 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
/* | |
=========================================== | |
JavaScript Hints & Tips | |
Compiled mainly from http://sharedfil.es/js-48hIfQE4XK.html | |
=========================================== | |
// onReady | |
document.addEventListener("DOMContentLoaded", function() { | |
// code... | |
}); | |
// jQuery-esque selector (>= IE8) | |
document.querySelectorAll('.price'); | |
// JSONP | |
var scr = document.createElement('script'); | |
scr.src = 'http://openexchangerates.org/latest.json?callback=formatCurrency'; | |
document.body.appendChild(scr); | |
// Modify classes | |
newDiv.classList.add("foo"); | |
newDiv.classList.toggle("foo"); | |
// onClick | |
[].forEach.call(document.querySelectorAll("a"), function(el) { | |
el.addEventListener("click", function() { | |
// code... | |
}); | |
}); | |
// append | |
document.body.appendChild(el); | |
// modify attributes | |
document.querySelector("img").setAttribute("alt", "My image"); | |
// get parent | |
var p = document.getElementById("about").parentNode; | |
// empty element | |
while(wrap.firstChild) wrap.removeChild(wrap.firstChild); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment