π What is Trace.js?
Trace.js is a lightweight jQuery plugin for highlighting words or phrases inside HTML elements.
π Features:
- β Supports case-sensitive and case-insensitive searches.
- β Highlights full or partial matches.
- β Works with dynamic content.
- β Zero dependencies! Just jQuery required.
β‘ Why I Built Trace.js
Recently, one of my junior developers needed to highlight a word inside a list of paragraphs dynamically. This gave me an idea what should I build next.
π¦ How to Install Trace.js
Method 1οΈβ£ Install via NPM
npm i trace-text-highlighter
Method 2οΈβ£ Use CDN
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/connectamitsahoo/trace.js@latest/dist/trace.min.js"></script>
π How to use Trace.js
$("#content").trace({
match: "highlight", // Word to highlight
color: "yellow", // Highlight color (default: yellow)
traceType: "full", // Only highlights full words (default: partial)
caseSensitive: true // Enables case-sensitive matching. (default: false)
});
π Real-World Use Cases
πΉ Search Result Highlighting β Highlight user search queries dynamically.
πΉ Content Emphasis β Highlight key terms in articles or documentation.
πΉ Live Text Filtering β Visually emphasize matching text in real-time.
π‘ Feedback & Contributions Welcome!
Trace.js is open-source under the MIT License. Check out the repo and feel free to contribute or report issues!
π GitHub Repo
π NPM Package
Let me know what you think! Drop a comment below. π
Top comments (0)