search is a jQuery Plug-in enables easy search and highlight/replace manipulation over the DOM text nodes
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

jQuery search plugin Build Status

This plugin makes easier search over text nodes of static or dynamical html content.

This plugin has been tested in Firefox 3+, Internet Explorer 7, 8, 9 and Chrome 11+

Main Features

  • searches and highlights/replaces text

  • previous/next or indexed search

  • searches over both dynamic and static HTML content

  • optional external dependencies


The plugin is open sourced under MIT license. If this license doesn't suit you mail me at n.martynenko (at)


Known Issues

Plugin hasn't been tested yet in many cases. So I would appreciate any feedback.

Getting started

var searcher = jQuery("#searchSelector").search(options);

Method "search" of jQuery object returns "searcher" object, which is used for search.


Plugin has the only one strong dependency — jQuery 1.4.2+. Though it optionaly depends on jQuery ScrollTo plugin (for smooth scrolling to selected element) and jQuery textSelect plugin (for highlighting of search's result rather than highlight the whole DOM-element).

Options of plugin

    //print debug information into console
    "debug" : false,
    //in case if it is set to false, searcher after it's creation calls nextConcurrence method
    //if you would like to do some other stuff rather than it, please use onCreate callback
    "createOnly" : true,
    //is case-sensitive search
    "caseSensitive" : false,
    //if it is set, then search result will be always updated in context container
    "searchSelector" : "",
    //start position
    //NOTE following:
    //1. position starts with 0.
    //2. if you call nextConcurrence method, it will be increased before searching element
    "position" : -1,
    //search of order
    // can be "up" (or true), "down" (or false)
    "searchOrder" : "down",
    //type of after finding behaviour
    // can be:
    // 1. highlight — highlight the whole element
    // 2. highlightSelected — highlight selected text of element
    // 3. replace — replace
    // 4. none — do nothing, usefull with afterSearch callback
    "searchType" : "highlight",
    //text to search. can be set via setText method
    "text" : null,
    //text to replace (when "searchType" is "replace" only)
    "replaceBy" : "",
    //if this parameter is true, page automatically scroll to selected element
    //NOTE: it might not work in case if selector is different than needed, use afterSearch callback in that case
    "scrollTo" : false,
    //callback called after creating of "searcher" object
    onCreate : function(){},
    //calback called before next search
    beforeSearch : function(){},
    //callback called after next search
    afterSearch : function(textEl){}

Plugin methods

  • reset — resets search position

  • getText — returns current search text

  • setText(newText) — updates search text; search position is set to default

  • getPosition — returns current search position

  • setPosition(newPostion) — sets new search position; if it is more than concurrences number, it will be reseted

  • getSearchOrder — returns current search order (string)

  • setSearchOrder(newSearchOrder) — change search order; search position won't be changed

  • getSearchType — returns current search type

  • setSearchType(newSearchType) — changessearch type; search position won't be changed

  • getConcurrencesNumber — returns number of search concurrences

  • nextСoncurrence(searchOrder) — finds next search concurrence; searchOrder — next/previous concurrence, if this parameter isn't set, default searchOrder is used

  • findConcurrence(position, searchType) — find N concurrence; position — index of search concurrence, if it isn't set, current position is used; searchType — type of behaviour after searching, if it isn't set default searchType is used