Skip to content

Instantly share code, notes, and snippets.

@andreyshr
Last active August 2, 2018 07:38
Show Gist options
  • Save andreyshr/80b0a41ce4d0ee384f62cc668aa10f9b to your computer and use it in GitHub Desktop.
Save andreyshr/80b0a41ce4d0ee384f62cc668aa10f9b to your computer and use it in GitHub Desktop.
sliceText(textNodes, symbols)
function sliceText(textNodes, symbols) {
textNodes.forEach(cur => {
const text = cur.innerText;
let sliced = text.slice(0,symbols);
if (sliced.length < text.length) {
sliced += '...';
cur.innerText = sliced;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment