I\'ve been trying to make a simple search inside a static HTML page using JQuery. I have to mention that this is just my first time working with JQuery.
I\'m trying
Here is mine: http://jsfiddle.net/x8rpY/1/
JS:
$('#searchfor').keyup(function(){
var page = $('#all_text');
var pageText = page.text().replace("","").replace("");
var searchedText = $('#searchfor').val();
var theRegEx = new RegExp("("+searchedText+")", "igm");
var newHtml = pageText.replace(theRegEx ,"$1");
page.html(newHtml);
});
CSS:
#all_text span
{
text-decoration:underline;
background-color:yellow;
}
Works for repeated search also.