Created
May 1, 2018 18:39
-
-
Save NickDeckerDevs/8414d704966947a47de982af8205cfb7 to your computer and use it in GitHub Desktop.
add nbsp to the last word of certain elements that you choose.
This file contains hidden or 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
| // target your items to be checked for oprhans, | |
| // avoid header and footer areas to keep script quick | |
| let contentToCheck = [ | |
| '.content-wrapper p', | |
| '.content-wrapper h1', | |
| '.content-wrapper h2', | |
| '.content-wrapper h3', | |
| '.content-wrapper h4' | |
| ]; | |
| for(let i = 0; i < contentToCheck.length; i++) { | |
| let items = document.querySelectorAll(contentToCheck[i]); | |
| for(let j = 0; j < items.length; j++) { | |
| let item = items[j]; | |
| let html = item.innerHTML; | |
| // 5 words is when we split | |
| if((html.split(' ').length - 1) > 4) { | |
| item.innerHTML = html.replace(/ ([^ ]*)$/,' $1'); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment