Download
User Rating: 0/5 ( 0 votes)
highlightRegex is a jQuery Plugin that highlight document text with a regular expression.
Source: github.com
1. INCLUDE JS FILES
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script src="highlightRegex.js"></script>
2. HTML
<div id="content">This is some text that will be highlighted with the regex <span id='regex'></span></div>
3. JAVASCRIPT
$(function() {
regex = /[aeiou]/ig
$('#content').highlightRegex(regex);
});
To clear the highlighting, just call $('#any.jquery.selector').highlightRegex(); (with no argument).
If you'd like to wrap with a different sort tag and/or class, use
$('#jquery.selector').highlightRegex( /some ([rR]egex)/, {
tagType: 'strong',
className: 'andHale'
});
Additional attributes can be set on the created tag
$('#jquery.selector').highlightRegex( /some ([rR]egex)/, {
attrs: {'data-color': 'blue'}
});