Q:

How to find the number of characters in a string using jQuery

0

How to find the number of characters in a string using jQuery

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the jQuery .length property

The jQuery .length property can be used to get or find out the number of characters in a string. You can also use this property to calculate the number of elements in a jQuery object.

Let's take a look at an example to understand how it basically works:

<script>
    $(document).ready(function(){
        var myStr = "      Paragraph of text with   multiple white     spaces before and after.       ";
        myStr.length; // Returns 81
        $.trim(myStr).length; // Returns 68
        myStr.replace(/ /g,'').length; // Returns 53
    });
</script>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

JavaScript / jQuery Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to remove the clickable behavior from a disabl... >>
<< How to remove white spaces from a string in jQuery...