如何删除按钮

How to remove button

我正在尝试删除

<button id="load-more-comments"></button>

如果评论不超过20条

加载更多按钮不应再出现

如果评论超过 21 则显示加载更多按钮

我的代码

var $parent = $("ol"),
$items = $parent.find("li"),
$loadMoreBtn = $("#load-more-comments"),
maxItems = 20,
hiddenClass = "visually-hidden";

// add visually hidden class to items beyond maxItems
$.each($items, function (idx, item) {
  if (idx > maxItems - 1) {
    $(this).addClass(hiddenClass);
    // if last comment, hide button see more


});


// onclick of show more button show more = maxItems
// if there are none left to show kill show more button
$loadMoreBtn.on("click", function (e) {
  $("." + hiddenClass).each(function (idx, item) {
    if (idx < maxItems - 1) {
      $(this).removeClass(hiddenClass);

    }
    // kill button if no more to show
    if ($("." + hiddenClass).size() === 0) {
      $loadMoreBtn.hide();

    }
  });
});

这是我的 CSS

.visually-hidden {
  position: absolute;
  overflow: hidden;
  clip: rect(0 0 0 0);
  height: 1px;
  width: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
}

很简单只要把这段代码放在

之后

hiddenClass = "visually-hidden";

代码:

if($items.length <= 20 ){
    $loadMoreBtn.hide();
}