I have a dom node in variable and i want to remove all enter/line break, tabs between the html tags. Basically i want to minify it without using external library. How can i do it.
var target = document.getElementById('myid');
var wrap = document.createElement('div');
wrap.appendChild(target.cloneNode(true));
wrap contains the node..
In this article, we will add a single line break using the <br> tag. It s used to give the single line break. It is the empty tag so it does not contain end tag.
Go to minifycode.com and click the CSS minifier tab. Then paste the CSS code into the input box and click the Minify CSS button. After the new minified code is generated, copy the code. Then go back to the css file of your website and replace the code with the new minified version.
Single line comments start with // . Any text between // and the end of the line will be ignored by JavaScript (will not be executed).
Not elegant, but should work
target.innerHTML = target.innerHTML.replace(/\n|\t/g, ' ');
You could replace the line breaks with an empty string target.replace(/(\r\n|\n|\r)/gm,"");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With