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:
- loop through divs inside container
- for each div, set color class name after 1000 milliseconds multiplied it's index in set of divs
Comments
Post a Comment