I am creating a script that'll iterate each element under 'body' and will check for its 'background-color'. If this background color matches to '#eb2c33', then the script will add a class to that element or else it'll move to the next element. I am using this so to avoid going into the html and put that class to elements manually. Here is my code.
$(document).ready(function (e) {
$('body *').each(function(index) {
var rgbg = $(this).css('background-color');
if(rgbg == "#eb2c33")
{
$(this).addClass('jcbg');
}
});
});
Now, this function works perfectly if i iterative over a specific div like header or footer etc. But when i iterate over the whole DOM, this function is not working at all. Please note that i am using a csshook that'll give me color values in Hex rather than rgb so please don't go for that. Any help?
Update:
I know the problem now. It was in that css hook from this post that i was using. i just removed that hook and directly have used rgb value and it started working perfectly. Here is my updated code
$(document).ready(function (e) {
$('body *').each(function(index) {
var rgbg = $(this).css('background-color');
if(rgbg == "rgb(235, 44, 51)")
{
$(this).addClass('jcbg');
}
});
});
Thanks @Guffa for your fiddle. It helped me.