Search This Blog

Saturday, 30 July 2016

How to remove the unwanted white space using javascript?

Html page:

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

Javascript page:

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

Output:

Hello World!

No comments:

Post a Comment