JSFiddle - React, Tailwind, and code Playground
by aflynt
HTML
<p class="storycontent">
<strong><img class="ms-rtePosition-2" src="/extaffairs/CitizenOnline/PublishingImages/News%20Images/2020/DS.jpg" alt="" style="margin: 5px; width: 200px; height: 300px;">Thursday, January 16, 2020 - Don Swinford</strong>, Georgia Power Facilities director, has announced his retirement following a successful 46-year career at Georgia Power. His retirement will be effective May 31, 2020. Don’s leadership and commitment to his team have been instrumental in Facilities Management’s success in supporting our company’s resources and people. </p>
<p id="demo">hello</p>
JavaScript
/*function truncate(str, no_words) {
return str.split(" ").splice(0,no_words).join(" ");
}
console.log(truncate($(".story-content:first").html(), 8));*/
function truncate(str, no_words) {
var truncStr = str.split(" ").splice(0,no_words);
return truncStr.join(" ");
}
console.log(truncate($(".storycontent:first").text().trim(), 25));
console.log(truncate($(".storycontent:first").text().trim(), 8));
var x = truncate($(".storycontent:first").text().trim(), 25);
document.getElementById("demo").innerHTML = x;