Skip to content

Instantly share code, notes, and snippets.

@yratof
Created July 22, 2015 13:30
Show Gist options
  • Save yratof/2d05e3dc73cad6f9475b to your computer and use it in GitHub Desktop.
Save yratof/2d05e3dc73cad6f9475b to your computer and use it in GitHub Desktop.
Inline Block space removal
// Inline block sorted out with javascript. Plain vanilla javascript.
// Technially, this removes unwanted nodes from inside a DOM node
var utils = {};
utils.clean = function(node) {
var child, i, len = node.childNodes.length;
if (len === 0) { return; }
// iterate backwards, as we are removing unwanted nodes
for (i = len; i > 0; i -= 1) {
child = node.childNodes[i - 1];
// comment node? or empty text node
if (child.nodeType === 8 || (child.nodeType === 3 && !/\S/.test(child.nodeValue) )) {
node.removeChild(child);
} else {
if (child.nodeType === 1) {
utils.clean(child);
}
}
}
};
document.documentElement.className='js';
function inlineBlock(){
var col = document.querySelectorAll('.columns');
var i; // <-- Counter
// Apply this to all elements
for (i = 0; i < col.length; i++){
utils.clean(col[i]);
}
}
inlineBlock();
jQuery(document).ready(function(){inlineBlock();});
/* Run this as a callback if using ajax
if(typeof inlineBlock === 'function') { inlineBlock(); } // Remove all inline block bollocks
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment