I have a HTML page which shows a Name dynamically. Now this name (FN LN) can be upto 240 charcaters. But at the UI side, I want to trim the FN/LN after about 50 characters and replace with ...
How can I do this using Javascript/jQuery
Use the String. slice() method to remove everything after a specific character, e.g. const removed = str. slice(0, str.
TrimLeft(), used to remove characters from the beginning of a string. TrimRight(), used to remove characters from the string's end. Trim(), used to remove characters from both ends. JavaScript's native functions, like those of many other languages, solely remove whitespace characters.
The newline character is \n in JavaScript and many other languages. All you need to do is add \n character whenever you require a line break to add a new line to a string.
To limit the string length, assign an integer number to the maxLength option. By default, the string length is unlimited.
$("#FN, #LN").each (function () {
if ($(this).text().length > 50)
$(this).text($(this).text().substring(0,50) + '...');
});
This should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With