jQuery/replaceWith()

解説
要素を指定された別のエレメントやHTMLと差し替え
sample1
  • 金木犀
  • 五葉松
  • 山茶花
sample1code
$(function(){
  $("#sample1ul li:eq(0)").click(function(){
	$(this).replaceWith(" li>落葉樹 /li>");
  });
  $("#sample1ul li:eq(1)").click(function(){
	$(this).replaceWith(" li>針葉樹 /li>");
  });
  $("#sample1ul li:eq(2)").click(function(){
	$(this).replaceWith(" li>常葉樹 /li>");
  });
});
sample2

sample2p

sample2code
$(function(){
  $("#s2Div p").click(function(){
  	$(this).replaceWith("span>s2Span/span>");
  });
});