javascript - jQuery usage of .filter -


i learning jquery. problem: have 3 component in container. font color black. change font color according class name of each div.

i able change 2 of them while fail change all. code belows:

index.html

<!doctype html> <html> <head>  </head> <body>     <div class="container">         <div class="red">old content</div>         <div class="black">old content</div>         <div class="blue">old content</div>     </div>  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script src="index.js"></script>  </body> </html> 

index.js

$(document).ready(function(){     $('.container div')         .delay(10000)         .css("color","blue")         .delay(10000)         .filter(".red")         .css("color", "red")         .delay(10000)         .filter(".black")         .css("color", "black");     }); 

please advice.

$('.container div').each(function(i, el) {     settimeout(function(){        $(this).css("color", $(this).attr('class'));     }, * 1000); }); 

explanation:

  1. loop through divs inside container
  2. for each div, set color class name after 1000 milliseconds multiplied it's index in set of divs

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -