Skip to content

Instantly share code, notes, and snippets.

@jahfer
Created May 13, 2012 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jahfer/2690856 to your computer and use it in GitHub Desktop.
Save jahfer/2690856 to your computer and use it in GitHub Desktop.
JavaScript: Hints
/*
===========================================
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