Skip to content

Instantly share code, notes, and snippets.

@egstad
Last active February 11, 2019 19:58
Show Gist options
  • Save egstad/0395253aa1a8d8f55b7e163f28858017 to your computer and use it in GitHub Desktop.
Save egstad/0395253aa1a8d8f55b7e163f28858017 to your computer and use it in GitHub Desktop.
Add line break in text (Javascript Class)
class BreakText {
constructor ( element, splitAfter ) {
this.element = document.querySelector( element );
this.stringOriginal = this.element.textContent;
this.stringNew = this.stringOriginal.replace( splitAfter, `${splitAfter}\u000A` );
this.element.innerText = this.stringNew;
}
}
// How to init
const foo = new BreakText( "ELEMENT_HERE", "STRING_HERE" );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment