jQuery/before()

解説 要素を指定の要素の前に追加
sample1
  • 1-1
  • 1-2
    • 1-2-1
    • 1-2-2
  • 1-3
sample1code
$(function(){
  $("#element1").before("(element1) ").css("color","navy");
});
		
sample2
sample2code
$(function(){
  var x = 0;
  $("#sample2Btn").click(function(){
	x++;
	$(this).before(x + ",");
  });
});
		
sample3
sample3code
$("#s3Btn").click(function(){
  var s3Pro = prompt();
  $(this).before("p>" + s3Pro + "/p>");
});