Add a new block, how to increase the number displayed in the content

the function to be done is

at first, only one block content is displayed 1

then when you press the add button, the same block will be added and the number displayed in the block content will increase by 2

.

continue to add 3, 4, 5.

the problem encountered is that I don"t know how to increase the number displayed in the block after adding the block. Please help me to see how to change it

.

Source code:

$(".container").on("click", ".addNewBlock", function(e) {
    var content = [];
   
    //
    var num = 1 ;
  
    content.push("<div>"+num+"</div>")
    $(this).parents(".container").append(content.join(""));
  
});
May.06,2021

var num = 1 ;
$(".container").on('click', '.addNewBlock', function(e) {
    var content = [];
   
    //
    num +=1;
  
    content.push('<div>'+num+'</div>')
    $(this).parents('.container').append(content.join(""));
  
});


$(".container").on('click', '.addNewBlock', function(e) {
    var content = [];
    content.push('<div>'+(content.length+1)+'</div>')
    $(this).parents('.container').append(content.join(""));
  
});
Menu