Last active
February 11, 2019 19:58
-
-
Save egstad/0395253aa1a8d8f55b7e163f28858017 to your computer and use it in GitHub Desktop.
Add line break in text (Javascript Class)
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
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