JSFiddle - React, Tailwind, and code Playground
HTML
<div id="params">
<div>
<div class="paramsprop">
<p>
test
</p>
</div>
</div>
<div>
<div class="paramsprop">
<p>
phone no.
</p>
<button id="addBtn" type="button" class="addButton">
+
</button>
</div>
</div>
<div>
<div class="paramsprop">
<p>
email
</p>
</div>
</div>
</div>
JavaScript
const add_button = document.getElementById('addBtn');
const paramsDiv = document.getElementById('params');
add_button.addEventListener('click', e => {
const data = e.target.parentElement.parentElement
// Grabs the parent element on height 2
console.log(data) // Got the expected data
// ran_value = Math.floor((Math.random() * 100000) + 1); // Tried this function to generate a random value for class
var data_new = data.cloneNode(true); // Created another clone instance of data
data_new.setAttribute('class', '1') //add class name
console.log(data_new) // changes the class name
// paramsDiv.appendChild(data_new);
paramsDiv.insertBefore(data_new, paramsDiv.firstChild);
});