「jQuery入門」remove()とempty()で要素を削除するコード

2017年10月14日

1.remove()
JSコード
$(function() {
$(“#testBtn").click(function() {
$(“#testDiv").remove();
});
});

htmlコード
<div id="testOne">サンプル11
<div id="testDiv">データ11
<p>データ11</p>
</div>
</div>
<input type="button" id="testBtn" value="remove">

2.empty()
JSコード
$(function() {
$(“#testBtn2").click(function() {
$(“#testDiv2").empty();
});
});

htmlコード
<div id="testTwo">サンプル22
<div id="testDiv2″>データ2
<p>データ2</p>
</div>
</div>
<input type="button" id="testBtn2″ value="empty">

JavaScript

Posted by arkgame