I'm teaching myself JQuery and as practice I'm creating a page in which the user enters text in an input field and all instances of that string is found in the body of the page and highlighted. I have been able achieve this functionality when the user clicks a button, but what I'd like to get it to do is continuously poll the input field and highlight the string.
Doing a continuous poll seems to crash the page.
$(document).ready(function(){
while(1==1){
var str = document.input.str.value;
$(function(){
$('p:contains('+str+')').each(function(){
var regex = new RegExp(str, "g");
$(this).html( $(this).html().replace( regex ,"<span class='hlt'>"+str+"</span>"));
});
});
}
});
Websites seem to have this kind of functionality all the time so I'm sure its doable, I just can't seem to find any info on it.
Thanks a lot!