I would use document.getElementsByClassName but IE does not support it.
I just want to improve querySelectorAll fallback for IE8.
Like others answered, the simple way is adding the function to Element.prototype with
this.querySelectorAll('.' + className);
But there are some problems:
/, $, *, etc.)That means there should be some "fixing", for example:
"abcd" -> ".abcd"
"a b cd" -> ".a.b.cd"
" a b " -> ".a.b "
"a/b$c d" -> ".a\/b\$c.d"
"1234" -> ".\000031234"
this.querySelectorAll(className
.replace(/(?=[^ \w])/g, '\\') // Escape non-word characters
.replace(/\b\d/g, '\\00003$&') // Escape digits at the beginning
.replace(/(^| +)(?!$| )/g, '.') // Add "." before classes, removing spaces
);