You need to separate the rgb values ββwith a space, since jQuery thus parses the value of .css("background-color") .
rgb(X, Y, Z) β² β²
This is the correct code:
if($(this).css("background-color")=="rgb(255, 193, 0)"){ alert("found"); }
Code snippet:
$(function(){ $(".testing").each(function(){ if($(this).css("background-color")=="rgb(255, 193, 0)") alert("found"); else alert("not found"); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <div class="parent"> <div class="testing" style="background-color:rgb(255,193,0)">Test</div> </div> <div class="parent"> <div class="testing" style="background-color:rgb(220, 4, 81)">Test</div> </div> <div class="parent"> <div class="testing" style="background-color:rgb(0, 186, 76)">Test</div> </div>
source share