Home > OS >  how to insert maximum 15 cards on add button
how to insert maximum 15 cards on add button

Time:04-10

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);
        }

    }

CodePudding user response:

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);
}

CodePudding user response:

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);}}

  • Related