Some times you need to remove spaces from a string, i have used replace() method to remove all spaces from a string.
Syntax
var str = string.replace(str1,str2);
Lets see how to use it.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
var msg = $("#divtext").html();
$("#msg").html(msg.replace(/\s/g, ""));
});
</script>
</head>
<body>
<form id="form1" runat="server">
<h4>
Before</h4>
<div id="divtext">
Welcome to aspxtutorial.com
<p>
Author:Aamir Hasan</p>
</div>
<h4>
After</h4>
<div id="msg">
</div>
</form>
</body>
</html>
Output

Download
Remove-white-spaces.aspx (1.14 kb)
See Live demo