-
-
Save nocodesupplyco/2753b0114a0a974c9b2c76d3787b9e8a to your computer and use it in GitHub Desktop.
Highlight Text From Search Query
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 src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/jquery.mark.min.js" integrity="sha256-4HLtjeVgH0eIB3aZ9mLYF6E8oU5chNdjU6p6rrXpl9U=" crossorigin="anonymous"></script> | |
<script> | |
$(function() { | |
var mark = function() { | |
// Read the keyword | |
var keyword = $("input[name='keyword']").val(); | |
// Determine selected options | |
var options = {}; | |
$("input[name='opt[]']").each(function() { | |
options[$(this).val()] = $(this).is(":checked"); | |
}); | |
// Remove previous marked elements and mark | |
// the new keyword inside the context | |
$(".context").unmark({ | |
done: function() { | |
$(".context").mark(keyword, options); | |
} | |
}); | |
}; | |
$("input[name='keyword']").on("input", mark); | |
$("input[type='checkbox']").on("change", mark); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment