Add Ellispes after max character count

Add Ellispes after max character count

by Nirvanachain

HTML

<a href="#" class="js-text">A link to something</a>

JavaScript

var element = document.querySelector('.js-text'),
    // innerText for IE, textContent for other browsers
    text = element.innerText || element.textContent,
    textArray = text.split(''),
    textArrayLength = textArray.length,
    maxCharacterCount = 7,
    newText = ''; 

if (textArrayLength > maxCharacterCount) {
  for (var i = 0; i < maxCharacterCount; i++) {
    newText += textArray[i];
  }
}

element.innerHTML = newText + ' ...';