$(function() { $("div").each(function(indx, el){ let color = $(el).css("backgroundColor"), [r,g,b] = color.match(/\d+/g); $(this).text([r,g,b]) }); });