Remove whitespace and line breaks between HTML elements using jQuery

Posted by mager on Stack Overflow See other posts from Stack Overflow or by mager
Published on 2009-10-08T17:37:23Z Indexed on 2010/04/06 18:43 UTC
Read the original article Hit count: 306

Using jQuery, I'd like to remove the whitespace and line breaks between HTML tags.

var widgetHTML = '    <div id="widget">        <h2>Widget</h2><p>Hi.</p>        </div>';

Should be:

alert(widgetHTML); // <div id="widget"><h2>Widget</h2><p>Hi.</p></div>

I think the pattern I will need is:

>[\s]*<

Can this be accomplished without using regex?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about string-manipulation