(function() {
//Store a reference to the head object, window in the browser or global on the server
var rootObject = this;
var doc = rootObject.document;
//return a new hippo object containing the node elements descibed by the elements parameter
var hippo = function(elements, context) {
return new CreateHippoObject(elements, context);
};
var CreateHippoObject = function(elements, context) {
//if no elements assume html element was sent
if (!elements) {
this.length = 1;
this[0] = document.documentElement;
return this;
}
//if HTML string, construct domfragment, fill object, then return object
if (typeof elements === 'string' && elements.charAt(0) === "<" && elements.charAt(elements.length - 1) === ">" && elements.length >= 3) {
var divElm = document.createElement('div');
var docFrag = document.createDocumentFragment();
docFrag.appendChild(divElm);
docFrag.querySelector('div').innerHTML = elements;
this.length = 1;
this[0] = docFrag.querySelector('div').firstChild;
return this;
}
//if a single element node reference is passed, fill object, return object
if (typeof elements === 'object' && elements.nodeName) {
this.length = 1;
this[0] = elements;
return this;
}
//other wise assume selector string, nodelist, or array, and use context if its passed
var nodes;
if (typeof elements !== 'string') { //its not a string so its an array or nodelist
nodes = elements;
} else { //if its a string create a nodelist, use context if provided
nodes = (doc.querySelectorAll(context)[0] || doc).querySelectorAll(elements);
}
//loop over array or nodelist and place in fill object
for (var i = 0; i < nodes.length; i++) {
this[i] =...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.