Skip to content

Instantly share code, notes, and snippets.

@joshuaadrian
Last active July 7, 2021 19:23
Show Gist options
  • Save joshuaadrian/c342ea310acf93000c5f to your computer and use it in GitHub Desktop.
Save joshuaadrian/c342ea310acf93000c5f to your computer and use it in GitHub Desktop.
My vanilla js utilities library
/*
* These are supported IE9+
* /
/*
* Initialization variables and functions
*/
var jsPresent = 'querySelector' in document && 'addEventListener' in window && "classList" in document.createElement("_") ? true : false;
if ( jsPresent ) { document.documentElement.className += 'js'; }
/*
* Object manipulation funtions
*/
var extend = function(obj, src) {
Object.keys(src).forEach(function(key) { obj[key] = src[key]; });
return obj;
}
var each = function( selector, callbackFunction ) {
len = selector.length;
for (var i=0; i<len; i++) {
console.log( selector[i].innerHTML );
}
}
/*
* Class manipulation functions
* Use classList DOM api https://developer.mozilla.org/en-US/docs/Web/API/Element/classList
*/
/*
* Selector manipulation methods
* Use querySelector and querySelectorAll methods https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelector
* and https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelectorAll
*/
/*
* Custom JS Starts here
*/
document.addEventListener("DOMContentLoaded", function() {
// Code goes here
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment