Last active
July 7, 2021 19:23
-
-
Save joshuaadrian/c342ea310acf93000c5f to your computer and use it in GitHub Desktop.
My vanilla js utilities library
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
/* | |
* 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