如何删除特定div id中的div元素

时间:2017-05-19 11:18:59

标签: javascript jquery html css

我想删除所有div为facebooktwitterLinkedIngooglePlus且父ID为 show-share-count

怎么做?



$("div").remove(".facebook");
$("div").remove(".twitter");
$("div").remove(".linkedIn");
$("div").remove(".googlePlus");

<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<div id="show-share-count">
  <div class="facebook">Facebook</div>
  <div class="twitter">Twitter</div>
  <div class="linkedIn">LinkedIn</div>
  <div class="googlePlus">Google Plus</div>
  <div class="share-count">Total Count</div>
</div>
<br /><br />
<div class="facebook">Facebook</div>
<div class="twitter">Twitter</div>
<div class="linkedIn">LinkedIn</div>
<div class="googlePlus">Google Plus</div>
<div class="share-count">Total Count</div>
&#13;
&#13;
&#13;

6 个答案:

答案 0 :(得分:4)

你只能在脚本部分只执行一行。

<script>
$("#show-share-count").find(".facebook, .twitter, .linkedIn, .googlePlus").remove();
</script>

答案 1 :(得分:2)

只需使用以下脚本

$('#show-share-count .facebook, #show-share-count .twitter, #show-share-count .linkedIn, #show-share-count .googlePlus, #show-share-count .share-count').remove();
  

或者您可以使用.children() ..

$("#show-share-count").children(".facebook , .twitter , .linkedIn, .googlePlus").remove();

答案 2 :(得分:1)

这样做。children()。他们会找到show-share-count

的儿童元素

$("#show-share-count").children(".facebook , .twitter , .linkedIn, .googlePlus").remove()
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="show-share-count">
  <div class="facebook">Facebook</div>
  <div class="twitter">Twitter</div>
  <div class="linkedIn">LinkedIn</div>
  <div class="googlePlus">Google Plus</div>
  <div class="share-count">Total Count</div>
</div>
<br /><br />
<div class="facebook">Facebook</div>
<div class="twitter">Twitter</div>
<div class="linkedIn">LinkedIn</div>
<div class="googlePlus">Google Plus</div>
<div class="share-count">Total Count</div>
</div>

答案 3 :(得分:1)

这是你可以做到的:

$("button").click(function() {
  $("#show-share-count").find(".facebook, .twitter, .linkedIn, .googlePlus, .share-count").remove();
});

Here is the JSFiddle demo

答案 4 :(得分:0)

如果要清空整个div

,可以尝试使用Jquery中的.empty

https://api.jquery.com/empty/

bool interpolate(const Mat &im, float ofsx, float ofsy, float a11, float a12, float a21, float a22, Mat &res)
{         
   bool ret = false;
   // input size (-1 for the safe bilinear interpolation)
   const int width = im.cols-1;
   const int height = im.rows-1;
   // output size
   const int halfWidth  = res.cols >> 1;
   const int halfHeight = res.rows >> 1;
   float *out = res.ptr<float>(0);
   const float *imptr  = im.ptr<float>(0);
   for (int j=-halfHeight; j<=halfHeight; ++j)
   {
      const float rx = ofsx + j * a12;
      const float ry = ofsy + j * a22;
      #pragma omp simd
      for(int i=-halfWidth; i<=halfWidth; ++i, out++)
      {
         float wx = rx + i * a11;
         float wy = ry + i * a21;
         const int x = (int) floor(wx);
         const int y = (int) floor(wy);
         if (x >= 0 && y >= 0 && x < width && y < height)
         {
            // compute weights
            wx -= x; wy -= y;
            int rowOffset = y*im.cols;
            int rowOffset1 = (y+1)*im.cols;
            // bilinear interpolation
            *out =
                (1.0f - wy) * ((1.0f - wx) * imptr[rowOffset+x]   + wx * imptr[rowOffset+x+1]) +
                (       wy) * ((1.0f - wx) * imptr[rowOffset1+x] + wx * imptr[rowOffset1+x+1]);
         } else {
            *out = 0;
            ret =  true; // touching boundary of the input            
         }
      }
   }
   return ret;
}

如果你想删除一个特定的div

答案 5 :(得分:0)

您也可以在下面使用:

$('#show-share-count .facebook,.twitter,.linkedIn,.googlePlus,.share-count').remove();