Skip to content

Instantly share code, notes, and snippets.

@bga
Created June 27, 2010 22:30
Show Gist options
  • Save bga/455221 to your computer and use it in GitHub Desktop.
Save bga/455221 to your computer and use it in GitHub Desktop.
// very basic example and don`t remember api. Sorry
var firstWord = 'hello', lastWord = 'world!';
var firstNode = document.evaluate('//text()[contets(.,"' + firstWord + '")]', root ....).snapshotItem(0);
var lastNode = document.evaluate('//text()[contets(.,"' + lastWord + '")]', root ....).snapshotItem(0);
var range = document.createRange();
range.setStart(firstNode, firstNode.data.indexOf(firstWord));
range.setEnd(lastNode, lastNode.data.lastIndexOf(lastWord) + lastWord.length);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment