Skip to content

Instantly share code, notes, and snippets.

@0xack13
Created December 1, 2012 23:10
Show Gist options
  • Select an option

  • Save 0xack13/4185801 to your computer and use it in GitHub Desktop.

Select an option

Save 0xack13/4185801 to your computer and use it in GitHub Desktop.
Highlight selected text without jquery
var selection = window.getSelection();
var range = selection.getRangeAt(0);
var newNode = document.createElement("span");
newNode.setAttribute("style", "background-color: pink;");
range.surroundContents(newNode);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment