How to remove all spaces from string in JQuery?

Category > JQUERY || Published on : Tuesday, April 6, 2021 || Views: 1595 || remove all spaces from string in JQuery


Here Pawan Kumar will explain how to How to remove all spaces from string in JQuery?

<html lang="en">
<head>
    <title>How to remove all spaces from string in JQuery?</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
    <div class="container text-center border">
        <textarea class="content-box" cols="55" rows="2">

            Some text with whitespace   in between   . please check this demo.

        </textarea>
        <button class="btn btn-primary mx-auto d-block mt-4 ">Remove White Space</button>
    </div>
    <script type="text/javascript">
        $("button").click(function(){
            myText = $(".content-box").val();
            var remove_space = myText.replace(/ /g,'');
            alert(remove_space);
        });
    </script>
</body>
</html>

 

Download Source Codes