我有以下jQuery代码。我想做的是我想清空am-container,但我无法这样做。

jQuery(document).find("div[id='am-container']").html('');


以下是我的HTML结构。

<div class="mid-part-right">
 <div class="match-image">
  <div class="main-gallary">
   <div class="container">
    <div id="am-container" class="am-container">
     <a class="draggable am-wrapper" href="#" style="width: 233px; height: 133px; margin: 2px;">
     <a class="draggable am-wrapper" href="#" style="width: 233px; height: 133px; margin: 2px;">
<a class="draggable am-wrapper" href="#" style="width: 263px; height: 133px; margin: 2px;">
    </div>
   </div>
  </div>
 </div>
</div>


这是完整的代码段:



jQuery(document).find("div[id='am-container']").html('');

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="mid-part-right">
  <div class="match-image">
    <div class="main-gallary">
      <div class="container">
        <div id="am-container" class="am-container">
          <a class="draggable am-wrapper" href="#" style="width: 233px; height: 133px; margin: 2px;">
            <a class="draggable am-wrapper" href="#" style="width: 233px; height: 133px; margin: 2px;">
              <a class="draggable am-wrapper" href="#" style="width: 263px; height: 133px; margin: 2px;">
        </div>
      </div>
    </div>
  </div>
</div>

最佳答案

听起来您想删除元素am-container而不是它包含的内容,请尝试执行此操作

$('#am-container').remove();

10-08 18:21