ItSolutionStuff.com

How to Get Number of Characters in a String in JQuery?

By Hardik Savani • July 21, 2023
jQuery

Now, let's see post of jquery count number of characters in string. we will help you to give example of get number of characters in string jquery. This article goes in detailed on find number of characters in a string jquery.

I will give you three example that will help to get count number of characters in string using jquery. so let's see bellow example.

Example: Count Characters

<!DOCTYPE html>

<html>

<head>

<title>jquery count number of characters in string - itsolutionstuff.com</title>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

</head>

<body>

<h1>jquery count number of characters in string - itsolutionstuff.com</h1>

<input type="text" name="string" value="This is example" class="input1">

<button class="button1">Click Me!</button>

<script>

$(document).ready(function(){

$('.button1').click(function(){

var countInput = $('.input1').val().length;

console.log(countInput);

});

});

</script>

</body>

</html>

Example: Count Characters without Space

<!DOCTYPE html>

<html>

<head>

<title>jquery count number of characters in string - itsolutionstuff.com</title>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

</head>

<body>

<h1>jquery count number of characters in string - itsolutionstuff.com</h1>

<input type="text" name="string" value="This is example" class="input2">

<button class="button2">Click Me!</button>

<script>

$(document).ready(function(){

$('.button2').click(function(){

var countInput = $('.input2').val().replace(/ /g,'').length;

console.log(countInput);

});

});

</script>

</body>

</html>

Example: Count Characters from String

<!DOCTYPE html>

<html>

<head>

<title>jquery count number of characters in string - itsolutionstuff.com</title>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

</head>

<body>

<h1>jquery count number of characters in string - itsolutionstuff.com</h1>

<script>

$(document).ready(function(){

var str = "This is example";

var count = str.length;

console.log(count);

});

</script>

</body>

</html>

I hope it can help you...

Tags: jQuery
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Set Radio Button Checked Based on Value using JQuery?

Read Now →

How to Get Checked Radio Button Value by Name in JQuery?

Read Now →

How to Check If Checkbox is Checked or Not in JQuery?

Read Now →

How to Get the Current URL using JQuery?

Read Now →

Check and Uncheck All Checkbox using JQuery Example

Read Now →

How to Allow Only One Checkbox Checked at a Time in JQuery?

Read Now →

How to Convert Line Breaks to br in jQuery ?

Read Now →