JSFiddle - React, Tailwind, and code Playground

by mikeys4u

HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

 
  <button id="doit">CLICK TO CLONE</button> 
 <div id="div1">div1</div>
 <div id="div2">div2</div>
 <div id="div3">div3</div>

JavaScript

$(document).ready(function(){
  $('#doit').click(function(){
var nextclone="div5";
 // get the last DIV which ID starts with ^= "div"
    var $div = $(nextclone);
 
 // Read the Number from that DIV's ID (i.e: 3 from "div3")
 // And increment that number by 1
var num=5;

 // Clone it and assign the new ID (i.e: from num 4 to ID "div4")
 var $new = $div.clone().prop('id', 'keyword'+num );
 
 // Clone it and assign the new ID (i.e: from num 4 to ID "div4")
 //var $new = $div.clone().prop('id', 'div'+num );
 
 // Finally insert $klon wherever you want
    $div.after( $new.text('div'+num) );
    
  });
  
});