Sunday 25 October 2020

Javascript highlight differences on a toggle switch

I am interested in creating a javascript toggle ability to highly the differences in rows. https://www.gsmarena.com/compare.php3?idPhone1=9847&idPhone2=9536#diff-*,*,*

so here is a base sand box. http://jsfiddle.net/5b37w6of/3/

I've seen some functions that could evaluate differences in text -- but I think with this it needs to go over each row - and on the differences apply a span tag around the different bits - then remove the span if the toggle is set back. Javascript compare strings and get end difference -- but there could be more than 2 cols

var s1 = "The quick brown fox",
  s2 = "The quick brown fox jumped over the fence",
  string1 = new Array(),
  string2 = new Array(),
  diff = new Array(),
  longString;

string1 = s1.split(" ");
string2 = s2.split(" ");

if (s1.length > s2.length) {
  longString = string1;
} else {
  longString = string2;
}

for (x = 0; x < longString.length; x++) {
  if (string1[x] != string2[x]) {
    diff.push(string2[x]);
  }
}

document.write("The difference in the strings is " + diff.join(" "));

here is a demo with the differences npm -- http://jsfiddle.net/8c4nt2e1/1/



from Javascript highlight differences on a toggle switch

No comments:

Post a Comment