Skip to content

Instantly share code, notes, and snippets.

@kangax
Created November 6, 2008 17:46
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 kangax/22653 to your computer and use it in GitHub Desktop.
Save kangax/22653 to your computer and use it in GitHub Desktop.
var sourceIndex = (function(){
var root = document.documentElement,
indexOf = Array.prototype.indexOf;
if ('sourceIndex' in root) {
if (root.sourceIndex === 0) { // Opera
return function(e) {
return e.sourceIndex + 1;
}
}
else if (root.sourceIndex === 1) { // IE
return function(e) {
return e.sourceIndex;
}
}
}
else if (indexOf && indexOf.call(document.getElementsByTagName('*'), document.documentElement) === 0) {
return function(e) {
return indexOf.call(e.ownerDocument.getElementsByTagName('*'), e) + 1;
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment