JSFiddle - React, Tailwind, and code Playground

by jansian

HTML

<div class="srch-results">


<div class="srch-Description2">Published by 'Hong Chee KUOK' using the Content and Structure Tool  
  …  
 ANNEX A: FOOD <strong>INNOVATION</strong> CLUSTER IN SINGAPORE 1. The Food <strong>Innovation</strong> Cluster (FIC) is a key initiative under the Food  
  …  
 </div>
 <div class="srch-Description2">Approved    by 'KUOK HONG CHEE' using the Content and  
  …  
 What is <strong>Innovation</strong> &amp; Entrepreneurship?  
  …  
 Strategies to Implement Structured <strong>Innovation</strong> and Entrepreneurship Programme in school  
  …  
 </div>
 </div>

CSS

.srch-Description2{
	border:1px solid black;
	margin-top:4px;
}

JavaScript

$(document).ready(function(){
	$('div.srch-results .srch-Description2').each(function(){
		var $str = $(this).text().toLowerCase();
		var dummyText = $str.replace(/\s/g,'');
		
		var startIndex = Math.max( dummyText.indexOf("approvedby"), dummyText.indexOf("publishedby"));
		alert(startIndex);
		if(startIndex >= 0){
			var $remove = $str.substr(startIndex, $str.indexOf('…')+4);
			
			var $newDesc = $str.replace($remove, '');
			$(this).text($newDesc);
		}
	});
});