I recently made a very simple selection using jQuery and the main plugin. It looks like this:
$ ('myButton'). click (function () {
.$ ('body') highlight ($ ('# myInputText') Val ().);
});
But I am wondering how I can make Chrome as a selection, I mean the selection of letters whenever I type text in a text box without sending. I think it's possible to use the keyup event ... Any ideas?
Thanks Andy, I changed 'this [0]' to 'search [i]' in your code and it works if there is only one tag 'p'
$(document).ready(function(){
var search = ['p', 'div', 'span'];
$("#highlighter").bind('keyup', function(e){
var pattern = $(this).val();
$.each(search, function(i){
var str = search[i];
var orgText = $(str).text();
orgText = orgText.replace(pattern, function($1){
return "<span style='background-color: red;'>" + $1 + "</span>"
});
$(str).html(orgText);
});
});
});
source
share