jQuery/each()

解説
繰り返しで実行される関数
$.each(対象のオブジェクト, function(index, val) {
  繰り返し実行する処理
});)
array = ["aaa", "bbb", "ccc"];
$.each(array, function(index, val) {
  $('ul').append("li>" + index + ":" + val + "/li>");
});
sample1
sample1code
$(function(){
  $("#sample1btn").click(function(){
  	$( ".sample1box" ).each(function( i ) {
    $( this ).css("display","inline-block").fadeIn().fadeOut( 1000 * ( i + 1 ) );
	});
  });
});
sample2

sample2p

sample2code
$(function(){
  $("#sample2p").click(function () {
    $(this).each(function(){
      if (this.style.color != "orange") {
        this.style.color = "orange";
      } else {
        this.style.color = "";
      }
    });
  });
});
sample3
s3Div01
s3Div02
s3Div03
sample3code
$("#s3Btn").on("click", function(){
  $(".s3Div").each(function(i, element){
    console.log(i + ": " + $(element).text());
  });
  $(".s3Div").each(function(i) {
    console.log(i + ": " + $(this).text());
  });
});
	
sample4
sample4code
$("#s4Btn").on("click", function(){
  var s4Obj = {"ソヨゴ":"常緑広葉樹", "松":"常緑針葉樹", "イチョウ":"落葉針葉樹"};
  $.each(s4Obj, function(key, val) {
  	var s4Ul = document.createElement("ul");
  	s4Ul.style.listStyle = "none";
  	$("#s4Btn").before(s4Ul)
    $(s4Ul).append("li>" + key + '(' + val + ")/li>");
  });
});
	
sample5
sample5code
$("#s5Btn").on("click", function(){
  var s5Array = ["紅葉", "山茶花", "アジサイ"];
  $.each(s5Array, function(index, val){
  	var s5Ul = document.createElement("ul");
  	$("#s5Btn").before(s5Ul);
  	$(s5Ul).append("li>" + index + "." + val + "/li>")
  	.css("list-style-type", "none");
  });
});