-
-
Save danheberden/1038635 to your computer and use it in GitHub Desktop.
Challenge Accepted.
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
getEl = (function (doc) { | |
var getElementsByClassName = (function () { | |
return doc.getElementsByClassName ? | |
function (selector) { | |
return doc.getElementsByClassName(selector.split('.').pop()); | |
} : function (selector) { | |
var parts = selector.split("."), | |
tags = document.getElementsByTagName(parts[0] || "*"), | |
matches = [], | |
classes, i, iLength, c, cLength; | |
for (i = 0, iLength = tags.length; i < iLength; i++) { | |
classes = ("" + tags[i].className).split(" "); | |
for (c = 0, cLength = classes.length; c < cLength; c++) { | |
if (classes[c] == parts[1]) { | |
matches.push(tags[i]); | |
break; | |
} | |
} | |
} | |
return matches; | |
} | |
})(); | |
return doc.querySelectorAll ? | |
function (selector) { | |
return doc.querySelectorAll(selector); | |
} : function (selector) { | |
var id; | |
if ((id = selector.split("#")).length > 1) { | |
return document.getElementById(id.pop()); | |
} else { | |
return getElementsByClassName(selector); | |
} | |
} | |
})(document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment