javascript - How to find element has specific color using jquery -


here html code

<ul id="components">     <li>computer</li>     <li>mouse</li>     <li>keyboard</li>     <li>printer</li>     <li>cpu</li> </ul> 
#components li:first-child{     color:red; } #components li: nth-child(2){     color:blue; } #components li: nth-child(3){     color:red; } #components li: nth-child(4){     color:red; } #components li: nth-child(5){     color:green; } 

what need jquery function can find li elements in red color , can convert background yellow

i mean like

$("#components").find(li elements in red color).css("backgound","yellow");  // find li elements in red color , change background yellow 

you can use .filter();

 $('ul li').filter(function() {     return $(this).css('color') == 'rgb(255, 0, 0)';   }).each(function() {     $(this).css('background-color', 'yellow');   })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.1/jquery.min.js"></script>  <ul id="components">    <li style="color:red">computer</li>    <li style="color:blue">mouse</li>    <li style="color:red">keyboard</li>    <li style="color:red">printer</li>    <li style="color:green">cpu</li>  </ul>


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -