I have any array vals_array
generated from .load(dictionary.txt) and now I want to compare each word in a contenteditable div with text wraps in <p>
, and if match any word from the array, it will wrap that word in a
Here is the text to array code:
var vals_array = [];
$.each(splitCntEditableTxt,function(key,val){
var nameFound = $.inArray(val.trim().toUpperCase(), dictionary);
if (nameFound === -1){
//alert(val + " No Match"); //DEBUG
} else {
//alert(val + " found in array"); //DEBUG
//$("#notes").append('<span class="OMG">'+val+'</span>');
vals_array.push(val);
}
});
and here is the code I'm thinking of using to compare filtered text and match them one by one from the array:
$('#notes').findText({query: vals_array}).each(function (){
//wrap matched word with <span>
});
The problem is, the text in <p>
sometimes have : , - spacing, \n \r and other non-word elements. So, how do I first filter out text in
leaving only pure words and then compare them with the array of vals_array
and if matched wrap it with a ?
Thank you very much~!!!