I want to reduce the text so that only displays 30 characters
Like
<p>Piqued favour stairs it enable exeter as seeing</p>
I want to be a text <p>Piqued favour stairs it...</p>
using javascript
("Show a certain number of text characters")
I want to reduce the text so that only displays 30 characters
Like
<p>Piqued favour stairs it enable exeter as seeing</p>
I want to be a text <p>Piqued favour stairs it...</p>
using javascript
("Show a certain number of text characters")
This is may be the most simple answer I can give using vanilla JS. It should work for you. Let me know, if not.
const trimSize = 20;
let text = '<p>Something that is too big and you want to trim, and then renddeer in your HTML page.</p>';
let content = text.substring(3, text.length - 4);
let trimmedText = '<p>' + content.substring(0, trimSize) + '<\p>';
console.log(trimmedText);
This might be the answer to your question:
const trim = (data, len) =>
data.replace(/(<(\w+)[^>]*?>)(\w.*?)<\/\2>/g,
match => match.replace(/(?=>).*(?=<\/)/,
match => match.length > len ? match.substr(0, len) : match
))
console.log(trim(`<div class="blog_contents"><h3 id="foo123">Facebook launches the application of a special communication companies</h3></div> `, 20))