I am new to JavaScript and jQuery.
I have a variable named as str in JavaScript and it contains very long text, saying something like
"A quick brown fox jumps over a lazy dog".
I want to wrap it and assign it to the same variable str by inserting the proper \n or br/ tags at the correct places.
I don’t want to use CSS etc. Could you please tell me how to do it with a proper function in JavaScript which takes the str and returns the proper formatted text to it?
Something like:
str = somefunction(str, maxchar);
I tried a lot but unfortunately nothing turned up the way I wanted it to be! 🙁
Any help will be much appreciated…
This should insert a line break at the nearest whitespace of maxChar: