HTML
CSS
JS
Result
HTML
<!DOCTYPE html> <html> <head> <title>Count the number of characters in a string without space using jQuery</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> </head> <body> <h1>Count the number of characters in a string without space using jQuery</h1> <input type="text" name="string" value="welcome to w3coderschool" class="input2"> <button class="clkbutton">Click Me!</button> </body> </html>
CSS
JS
$(document).ready(function(){ $('.clkbutton').click(function(){ var countInput = $('.input2').val().replace(/ /g,'').length; alert(countInput); }); });
How to find the number of characters in a string without space using jQuery?