jQuery/prepend()

解説 要素を指定の要素の前に追加
sample1
  • 1-1
  • 1-2
    • 1-2-1
    • 1-2-2
  • 1-3
sample1code
$(function(){
  $("#element1").prepend("(element1) ").css("color","navy");
});
	
sample2
sample2code
$(function(){
  var x = 0;
  $("#s2Btn").click(function(){
	x++;
	$(this).prepend(x +",");
  });
});
	
sample3
  • element10
sample3code
$(function(){
  var s3Count = 10;
  $("#s3Btn").on("click", function(){
  	s3Count--;
  	$("#s3Ul").prepend("li>" + "element" +s3Count + "/li>");
  	if(s3Count == 1){
  	  $(this).off("click");
  	}
  });
});