I have a function addFrom
which is triggered by a button. I would like to reuse changing the target ID and class. It works when I don't add any arguments. This is done using $(document).ready(function()
as shown below, but when I try to use an argument it works only the first time
I don't understand how can I use the function passing some arguments using $(document).ready
.
function addForm(TF) {
var $templateForm = $(TF);
console.log($templateForm)
}
$(document).ready(function() {
$('#add').click(addForm('#form2'));
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<body>
<a id="add" href="#">Add form</a>
</body>