簡體   English   中英

清空整個鄰居div部分

[英]Empty the entire neighbor div section

我有兩個div parent節,當我單擊任一.parent keywordsubmit按鈕時,我想清空其鄰居。 但是以下代碼不起作用:

   $('.parent').each(function() {    
    $(.keywordsubmit).click(function(e){         
      $(this).parent().siblings('#phpcom').empty();    
    });
   });

HTML代碼:

<div>

 <div class="parent">
  <select>
  <option>AAA</option>
  </select>
  <inputtype="text">
  <button type="submit" class="keywordsubmit">Submit</button>       
  <div class="area"></div>
 </div>

 <div class="parent">
  <select>
  <option>AAA</option>
  </select>
  <inputtype="text">
  <button type="submit" class="keywordsubmit">Submit</button>       
  <div class="area"></div>
 </div>

 <div id="phpcom">.............</div>

</div>

我也嘗試過closest()next() ,但似乎缺少了一些東西。 任何幫助,將不勝感激。

$('.keywordsubmit').click(function(){
   $('#phpcom').empty();
});

嘗試這個

JSFIDDLE

$('.keywordsubmit').click(function(){
    greatParent = $(this).parents('.parent').parent();
    $("#phpcom",greatParent).empty();

});

只要這樣做:

$('.keywordsubmit').click(function(){
   $(this).closest('.parent').next().empty();
});

試試下面的代碼,它可能對您有幫助

$('.parent').each(function() {    
$(.keywordsubmit).click(function(e){   
$('.parent').hide();  
$(this).parent().show();  
});
});

使用此JSFIDDLE

$('.keywordsubmit').click(function(){
$('.parent').hide();
$(this).parent().show();
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM