$( document ).ready(function() {
alert(solution());
});
function solution() {
// write your code in Javascript
//
// you can access DOM Tree using DOM Object Model:
// document.getElementsByTagName
// or using jQuery:
// $('some_tag')
//
// please note that element.innerText is not supported,
// you can use element.textContent instead.
var outPutText = '';
//Loop through each row of table.
$('table').find('tr').each (function() {
// Loop through of each cell of row.
$(this).find('td').each (function() {
// find current cell text.
var cellText = $(this).html();
//Get background color and text color.
var $backColor = getHexValueFromRGB($(this).css("background-color"));
var $color = getHexValueFromRGB($(this).css("color"));
//If background color and text color are same, then skip that cell text.
if($backColor !== $color) {
outPutText = outPutText + cellText;
}
});
});
return outPutText;
}
//Function to get hex format of a rgb color
function getHexValueFromRGB(rgbVal){
var rgbArr = rgbVal.replace(/\s/g,'').match(/^rgba?\((\d+),(\d+),(\d+)/i);
//Calculate hex value.
var hexVal = (rgbArr && rgbArr.length === 4)
? "#" +
("0" + parseInt(rgbArr[1],10).toString(16)).slice(-2) +
("0" + parseInt(rgbArr[2],10).toString(16)).slice(-2) +
("0" + parseInt(rgbArr[3],10).toString(16)).slice(-2)
: rgbVal;
//Return calculated hex value.
return hexVal;
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.