「jquery」empty()で各要素の子要素を空にするサンプル

書式
$(selector).empty()
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#cft").empty();
});
});
</script>
</head>
<body>
<div id="cft" style="height:120px;width:200px;border:1px solid black;background-color:green;">
asss.
<p>AA01.</p>
<p>BB02.</p>
</div>
<br>
<button>テスト</button>
</body>
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("#cft").empty(); }); }); </script> </head> <body> <div id="cft" style="height:120px;width:200px;border:1px solid black;background-color:green;"> asss. <p>AA01.</p> <p>BB02.</p> </div> <br> <button>テスト</button> </body>
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("#cft").empty();
  });
});
</script>
</head>
<body>

<div id="cft" style="height:120px;width:200px;border:1px solid black;background-color:green;">

asss.
<p>AA01.</p>
<p>BB02.</p>

</div>
<br>

<button>テスト</button>

</body>

 

jQuery

Posted by arkgame