Skip to content

jQuery plugin which searches an element for text and highlights using span wrappers

License

Notifications You must be signed in to change notification settings

npbenjohnson/jquery.highlight.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

jquery.highlight.js

jQuery plugin which searches an element for text and highlights by wrapping them in spans.

Usage

$('Element').highlight(terms, [options]);

Terms can be a string or array of strings.

Options (shown with defaults)

  {
    // Highlight highlights children, any other setting removes highlights
    action: 'highlight',
    // CSS class of highlight spans
    highlightClass: 'highlighted',
    // Comparable to REGEX meaning of greedy for highlights
    greedy: true,
    // Automatically calls unhighlight on element before performing a highlight
    autoClear: true
  }

Notes

  1. When highlighting, whitespace the the browser would compress before rendering is replaced in any elements containing text so that searching using terms with spaces in them has a better chance of correct identification.
  2. With autoClear turned off, adjacent spans aren't merged on subsequent searches, so after highlighting a of 'as', subsequently highlighting 'as' would create <span class="highlighted">a</span><span class="highlighted">s</span>

About

jQuery plugin which searches an element for text and highlights using span wrappers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published