如何在jQuery中选择最近或下一个div

时间:2018-10-19 14:22:12

标签: javascript php jquery

我有一个php while循环,其中有多个帖子输出,人们现在可以发表评论,我想隐藏单击提交按钮的帖子评论 这是我的代码

 <form method="POST"  action="" >
                <div class="commentdiv">
                  <input type="hidden" name="id" id="id" class="id" value="<?php echo $pixid;?>">
                  <input type="hidden" name="username" id="username"  value="<?php echo $activeusername;?>">
                  <input type="hidden" name="uid" id="uid"  value="<?php echo $id3;?>">
          <textarea style=""  name="comment" id="comment" class="comment"  placeholder="  comment here"></textarea>
         <button type="button" style="background-color: Transparent;
    background-repeat:no-repeat;
    border: none;
    cursor:pointer;
    overflow: hidden;
    color: #3897f0; font-weight:600;" class="submit" id="button_id">comment</button>

       </div>

          </form>

         <div id="comments" class="comments">
            <?php



$sql = "SELECT * FROM comment where post_id='$pixid' order by time2 desc limit 3";
$results = mysqli_query($con,$sql);
if (mysqli_num_rows($results)>0) {
  while ($row = mysqli_fetch_assoc($results)) {
    $commentid = $row['id'];
    $comment = $row['comment'];
    $string = covertHashtags($comment);
    echo "<p class='written'>";
    echo "<a href='users2?id=".$row['user_id']."' style='color:black !important;'><b>".$row['username']."</b></a>";
    echo "  ".$string;
     $sql3 = "SELECT * FROM comment where id ='$commentid' and user_id='$id' order by comment desc limit 5 ";
$results3 = mysqli_query($con,$sql3);
     if (mysqli_num_rows($results3)>0) {

      echo "<div class='dropdown'>
  <img src='ellipsis.png' class='dots'>
  <div class='dropdown-content'>
    <br><p  class='delete' data-delete=".$commentid.">delete</p>
  </div>
</div>";

    } 
    else{
      echo "";
    }

     echo "</p>";  


  }
}else{
  echo "";
}

            ?>

          </div>
      </div>
      <br><br>



    <?php } ?>

这都是一个while循环,因此如果我单击第一篇文章的“提交”按钮,那么所有输出现在都具有相同的类,因此我希望该篇文章的评论部分不会只显示特定文章的评论div而不显示所有文章

我尝试过

$(this).closest('.comments').next('.comments');

 $(this).closest('.comments');
$(this).next('.comments');

但是没有运气,回报是什么,请zzzz帮我

1 个答案:

答案 0 :(得分:1)

注释位于包含div的{​​{1}}旁边的form中。

因此,点击该button,将是:

button