var nodes = document.querySelectorAll('.className'),
className =' foo',
re = new RegExp('\\s*' + className + '\\s*', 'gi');
for (var i = 0, len = nodes.length; i < len; i++) {
var node = nodes[i];
node.className = node.className.replace(re, ' ').trim();
}