Skip to content

Instantly share code, notes, and snippets.

View wliwanag's full-sized avatar

William Liwanag wliwanag

View GitHub Profile
@wliwanag
wliwanag / Highlighter.js
Last active March 29, 2020 15:12
Highlight Substring From Html / Text Source
//NOTES: Requires Jquery - version 2.2.0 was used during development but may work on earlier version
// Add style by defining highlight class
/*Searh text highlighter*/
$highlighter = (function(){
function highlightHtml(source, searchInput) {
var node = $.type(source) == "object" ? source : $($.parseHTML("<div>" + source + "</div>"));
if (node.children().length > 0) {
//wrap the text contents with a span