var counter = 1; var limit = 3; function addInput(divName){ if (counter == limit) { alert("You have reached the limit of adding " + counter + " inputs"); } else { var newdiv = document.createElement('div'); newdiv.className = 'draggable'; newdiv.id = 'draggable6'; newdiv.innerHTML = "
Hello
"; document.getElementById(divName).appendChild(newdiv); counter++; } } function addElement() { var ni = document.getElementById('myDiv'); var numi = document.getElementById('theValue'); var num = (document.getElementById('theValue').value -1)+ 2; numi.value = num; var newdiv = document.createElement('div'); var divIdName = 'draggable'+num; newdiv.setAttribute('id',divIdName); newdiv.className = 'draggable'; newdiv.innerHTML = 'Element Number '+num+' has been added! Remove the div "'+divIdName+'"
'; ni.appendChild(newdiv); }