I have some javascript / jquery to clone a table with some input files and a button. After cloning the button doesn't seem to work anymore when it has the same class.
The situation:
When you click the add product, a row will be copied under the last row, so that a user can add an other product to the option. Here's an example:
There's an other button beneath those products: Create option. This button clones the first table (Option) and past it under the button. But after it has been copied, the button 'Add Product' doesnt seem to work anymore
I don't have any errors, so I don't know what I am doing wrong.
This is the code that I'm using to clone the tables:
<script type="text/javascript">
$(document).ready(function () {
$('.addproduct').click(function (e) {
// Clone a product and add it to the option.
e.preventDefault();
var item = document.getElementById('hiddenTemplate').cloneNode(true);
$('#hiddenTemplate').before(item);
$(item).removeAttr('id');
});
$('.addOption').click(function (e){
// Create a new option
e.preventDefault();
var item = document.getElementById('hiddenOption').cloneNode(true);
$('.newOption').append(item);
$(item).removeAttr('id');
$(item).addClass('tableOptions');
});
});
Could some1 explain to me what I'm doing and what might be an solution? My code isn't prefect atm i think and I'm open for learning!
Happy Coding!