I've the following string containing HTML. What would be sample code in JavaScript to remove leading and trailing white spaces that would appear in the rendering of this string? In other words: how can I obtain a string that would not show any leading or training white spaces in the HTML rendering, but otherwise be identical?
<p> </p>
<div> </div>
Trimming using JavaScript<br />
<br />
<br />
<br />
all leading and trailing white spaces
<p> </p>
<div> </div>
<p></p>get removed (if leading or trailing)? What about tags not meant to hold text, like an<img>? Should we only delete entire elements or should we e.g. trim<p> foo</p>to<p>foo</p>? What about literal newline and space characters between tags that with default CSS won't render but could withwhite-space: pre? What about<pre>elements? Probably there's more...