I am looking for a brief comparison of two arrays for any match.
I use this comparison to apply a specific style to any cell in a table that has relevant content. One array is a static list of content that must be contained in at least one table cell on the page. Another array is generated by jQuery and is the text of all the cells in the table.
The reason I have to compare the content with the applied style is that the HTML document will semantically change over time, created by different versions of excel (pretty awful looking code), and this script should take this into account. I know that the content I'm looking for to apply style in this document will never change, so I need to define all the matches for this content in order to apply styles to them.
So the code should be something like (in English):
For each table cell, compare the cell text with the contents of the array. If there is a match, apply this css to the table cell.
This is what I still have (and I know it is wrong):
$(document).ready(function(){ $("a.loader").click(function(event){ event.preventDefault(); var fileToLoad = $(this).attr("href"); var fileType = $(this).text(); var makes = new Array("ACURA","ALFA ROMEO","AMC","ASTON MARTIN","ASUNA","AUDI","BENTLEY","BMW","BRITISH LEYLAND","BUICK","CADILLAC","CHEVROLET","CHRYSLER","CITROEN","COLT","DACIA","DAEWOO","DELOREAN","DODGE","EAGLE","FERRARI","FIAT","FORD","GEO","GMC","HONDA","HUMMER","HYUNDAI","INFINITI","INNOCENTI","ISUZU","JAGUAR","JEEP","KIA","LADA","LAMBORGHINI","LANCIA","LAND ROVER","LEXUS","LINCOLN","LOTUS","MGB","MASERATI","MAYBACH","MAZDA","MERCEDES BENZ","MERCURY","MG","MINI","MITSUBISHI","MORGAN","NISSAN (Datsun)","OLDSMOBILE","PASSPORT","PEUGEOT","PLYMOUTH","PONTIAC","PORSCHE","RANGE ROVER","RENAULT","ROLLS-ROYCE / BENTLEY","SAAB","SATURN","SCION","SHELBY","SKODA","SMART","SUBARU","SUZUKI","TOYOTA","TRIUMPH","VOLKSWAGEN","VOLVO","YUGO","Acura","Alfa Romeo","Amc","Aston Martin","Asuna","Audi","Bentley","Bmw","British Leyland","Buick","Cadillac","Chevrolet","Chrysler","Citroen","Colt","Dacia","Daewoo","Delorean","Dodge","Eagle","Ferrari","Fiat","Ford","Geo","Gmc","Honda","Hummer","Hyundai","Infiniti","Innocenti","Isuzu","Jaguar","Jeep","Kia","Lada","Lamborghini","Lancia","Land Rover","Lexus","Lincoln","Lotus","MGB","Maserati","Maybach","Mazda","Mercedes Benz","Mercury","Mg","Mini","Mitsubishi","Morgan","Nissan (Datsun)","Oldsmobile","Passport","Peugeot","Plymouth","Pontiac","Porsche","Range Rover","Renault","Rolls-Royce / Bentley","Saab","Saturn","Scion","Shelby","Skoda","Smart","Subaru","Suzuki","Toyota","Triumph","Volkswagen","Volvo","Yugo"); $("div#carApp").html("<img src='images/loadingAnimation.gif' alt='LOADING...' />"); $("div#carApp").load(fileToLoad, function(){ $("#carApp style").children().remove(); $('#carApp td').removeAttr('style'); $('#carApp td').removeAttr('class'); $('#carApp table').removeAttr('class'); $('#carApp table').removeAttr('style'); $('#carApp table').removeAttr('width'); $('#carApp tr').removeAttr('style'); $('#carApp tr').removeAttr('class'); $('#carApp col').remove(); $('#carApp table').width('90%'); var content = $("#carApp table td"); jQuery.each(content, function() { var textValue = $(this).text(); if (jQuery.inArray(textValue, makes)==true) $(this).css("color","red"); }); }); }); });
Any ideas?