Does anyone know of a JQuery plugin which compares two strings and highlights the differences. I\'ve tried searching but although there is stuff out there I can\'t find a J
I wouldn't be looking for a jQuery plugin in your case. jQuery is a framework that helps handling the DOM changes and more, but there are not many string functions in jQuery.
Another one found through Google does almost the same as the one you reference: http://www.daftlogic.com/sandbox-javascript-compare-differences-between-strings.htm
edit It seems like the above mentioned script is the same one used by John Resig thanks for pointing that out danishgoel end edit
Your problem is that you want it to run over a list of items in a table?
You would not need jQuery for the actual check on differences, but you can use a for loop around it, or a jQuery each call around it.
Like this HTML:
- sentence 1
- sentence 2
- sentence 3
and this JavaScript:
var default = "my sentence";
$('#sentences li').each(function(){
var li = $(this);
var result = $('').html( diffString( default, li.text() ) );
li.append(result);
});
As you can see, here you use the jQuery each on a jQuery selector but you ask a regular JavaScript function. No need for a jQuery plugin to do exactly the same.