Created
February 27, 2017 03:21
-
-
Save lettucebo/a33ad24c97e243b1cf1bf3d1bc60d963 to your computer and use it in GitHub Desktop.
This file contains 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
<script> | |
function highlight(container, what, spanClass) { | |
var content = container.innerHTML, | |
pattern = new RegExp('(>[^<.]*)(' + what + ')([^<.]*)', 'g'), | |
replaceWith = '$1<span ' + (spanClass ? 'class="' + spanClass + '"' : '') + '">$2</span>$3', | |
highlighted = content.replace(pattern, replaceWith); | |
return (container.innerHTML = highlighted) !== content; | |
} | |
</script> | |
<style> | |
.highlight { | |
background-color: yellow; | |
} | |
.tab { | |
width: 200px; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment