DEV Community

Cover image for Introducing Trace.js – A Lightweight jQuery based Text Highlighter Plugin
Amit Sahoo
Amit Sahoo

Posted on

1

Introducing Trace.js – A Lightweight jQuery based Text Highlighter Plugin

🌟 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
Enter fullscreen mode Exit fullscreen mode

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>
Enter fullscreen mode Exit fullscreen mode

πŸ›  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) 
            });
Enter fullscreen mode Exit fullscreen mode

πŸ† 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. πŸš€

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More