Created
May 8, 2019 09:36
-
-
Save molochnyk/6dd8b8f7a7c27a6291c037775f0b4b9b to your computer and use it in GitHub Desktop.
cut-words
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sliceWords() { | |
let line = document.querySelectorAll('.secten_block_items_doc p'); | |
function cutWords(str, max = 20) { | |
str.forEach((el) => { | |
if(el.textContent.length > max) { | |
let string = el.textContent.trim().split(' ').slice(0, max).join() + ' ...'; | |
el.innerHTML = string; | |
} | |
}) | |
return str | |
} | |
cutWords(line); | |
} | |
sliceWords(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment