'how to insert maximum 15 cards on add button

This code is not working i have made a button adddmore in that the cards are appending when i click on it but i want to specific if i click on button more than 15 times the button should disable

function AddMore() {
        var counter = 0;

        var clonehtml = $(".manage").html();
        if(counter < 5) {
            counter++;  
            $("#manageview").append(clonehtml);
            
        }
        else {
           // $("#Addmore").attr('disabled',false);
        }

    }


Solution 1:[1]

You could move the counter outside the function but this is likely what you wanted

function AddMore() {
  const counter = $("#manageview").find(".manage").length;
  if (counter >= 5) return; // leave
  var clonehtml = $(".manage").html();
  $("#manageview").append(clonehtml);
}

You can do this too - I use eq(0) to only get one .manage element

const $manageView = $("#manageview")
function AddMore() {
  const counter = $manageView.find(".manage").length;
  $("#Addmore").attr('disabled',counter >= 5);
  if (counter >= 5) return; // leave
  var clone = $(".manage").eq(0).clone(true);
  $manageView.append(clone);
}

Solution 2:[2]

function AddMore() {
    var numitem = $(".galleryviewcard").length;
    var counter = 0;
    if (numitem < 16) {
        counter++;
        var clonehtml = $(".manage").html();
        $("#manageview").append(clonehtml);
    } else {
        $("#Addmore").prop('disabled', true);
    }

}

// This is just a sample script. Paste your real code (javascript or HTML) here.

if ('this_is' == /an_example/) {
    of_beautifier();
} else {
    var a = b ? (c % d) : e[f];
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mplungjan
Solution 2 DanielJ