Skip to content

Instantly share code, notes, and snippets.

@Hexodus
Last active April 17, 2017 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hexodus/7c4088ce2e7c6d60fd1e4d07bb809264 to your computer and use it in GitHub Desktop.
Save Hexodus/7c4088ce2e7c6d60fd1e4d07bb809264 to your computer and use it in GitHub Desktop.
Get text before certain character: str.substring(0, str.indexOf(":")); My full example : http://stackoverflow.com/questions/16470113/how-to-return-part-of-string-after-a-certain-character/16470330#16470330
var input_string = document.getElementById('my-input').innerText;
var output_element = document.getElementById('my-output');
//here we go
var right_text = input_string.substring(0, input_string.indexOf(":"));
output_element.innerText = right_text;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment