Fork me on GitHub

highlight.js

Highlight Keywords on Page with jQuery

Getting Started

Installing

Include in Your HTML

<!-- jQuery requires!-->
<script type="text/javascript" src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script type="text/javascript" src="path/jQuery.highlight.js"></script>

Usage

var cnt = $(selector).highlight('keyword', options);

//callback matches count
console.log(cnt);

option

Parameter Type Default Description
color String #000 Change font color
background String #ffff00 Change background color
bold boolean false text bold change
class String - Add class to keyword elements
ignoreCase boolean true
wholeWord boolean false

Example

Code

$(selector).highlight('the', {
    color: 'black',
    background: 'yellow',
    ignoreCase: true,
    wholeWord: false,
    bold: false
});

Result0 matches

jQuery is a cross-platform JavaScript library designed to simplify the client-side scripting of HTML.[3] jQuery is the most popular JavaScript library in use today, with installation on 65% of the top 10 million highest-trafficked sites on the Web.[4][5][6] jQuery is free, open-source software licensed under the MIT License.[2]

jQuery's syntax is designed to make it easier to navigate a document, select DOM elements, create animations, handle events, and develop Ajax applications. jQuery also provides capabilities for developers to create plug-ins on top of the JavaScript library. This enables developers to create abstractions for low-level interaction and animation, advanced effects and high-level, themeable widgets. The modular approach to the jQuery library allows the creation of powerful dynamic web pages and Web applications.

The set of jQuery core features—DOM element selections, traversal and manipulation—enabled by its selector engine (named "Sizzle" from v1.3), created a new "programming style", fusing algorithms and DOM data structures. This style influenced the architecture of other JavaScript frameworks like YUI v3 and Dojo, later stimulating the creation of the standard Selectors API.[7]

Microsoft and Nokia bundle jQuery on their platforms.[8] Microsoft includes it with Visual Studio[9] for use within Microsoft's ASP.NET AJAX and ASP.NET MVC frameworks while Nokia has integrated it into the Web Run-Time widget development platform.[10] jQuery has also been used in MediaWiki since version 1.16.