Skip to content

Instantly share code, notes, and snippets.

@drinks
Created July 12, 2010 13:44
Show Gist options
  • Save drinks/472471 to your computer and use it in GitHub Desktop.
Save drinks/472471 to your computer and use it in GitHub Desktop.
if ( document.getElementsByClassName && document.documentElement.getElementsByClassName ) (function(){
var div = document.createElement("div");
div.innerHTML = "<div class='test e'></div><div class='test'></div>";
// Opera can't find a second classname (in 9.6)
if ( div.getElementsByClassName("e").length === 0 )
return;
// Safari caches class attributes, doesn't catch changes (in 3.2)
div.lastChild.className = "e";
if ( div.getElementsByClassName("e").length === 1 )
return;
Expr.order.splice(1, 0, "CLASS");
Expr.find.CLASS = function(match, context, isXML) {
if ( typeof context.getElementsByClassName !== "undefined" && !isXML ) {
return context.getElementsByClassName(match[1]);
}
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment