I have implement a quick solution if you just understand what I am doing you can get a solution for this problem
I have 2 methods one is counting line numbers, the other one returns text in the exact line by given lineNumber.
by this approach if line counter greater than 2, then get the first 2 lines of text create another templete and append it to container
Here is my Fiddle
$( document ).ready(function() {
function countLines() {
var divHeight = parseInt( $(".maxTwoLine").height() );
var lineHeight = parseInt($('.maxTwoLine').css('line-height'));
return divHeight/lineHeight;
}
function GetTextLine(lineNumber){
var lines = $('.maxTwoLine').text().split(' ');
console.log(lines);
for(var i = 0;i < lines.length;i++){
if(i === lineNumber)
{
return lines[i];
}
}
}
$(".clickB").click(function(){
var lineCounter = countLines();
if(lineCounter>1)
{
var allText = $('.maxTwoLine').text();
var firstLineText = GetTextLine(0);
var secondLineText = GetTextLine(1);
var template = firstLineText + '<div class="ellipsisText">' + secondLineText + '</div>';
$('.maxTwoLine').text("");
$('.maxTwoLine').append(template);
allText = allText.replace(secondLineText, template);
}
var container = ".maxTwoLine";
});
});