<!DOCTYPE html>
<html>
<body>

<p>Click the button to alert the string with removed whitespace.</p>

<button onclick="myFunction()">Try it</button>

<p><strong>Note:</strong> The trim() method is not supported in Internet Explorer 8 and earlier versions.</p>

<script>
function myFunction() {
    var str = "       Hello World!       ";
    alert(str.trim());
}
</script>

</body>
</html>