I have a loop that create form fields (input) dynamically via a loop. I set the ID as a property within the loop so each item has a different ID (I need to attach different parameters for each item).
I keep getting the error ...not a function which shows the element is not created when my click event is executed... even though my onclick event is placed after the .appendChild method?
Is there something I am not getting?
// Iterate through array to create form fields for filter
for (var i = 0; i < filterUnique.length; i++) {
var input = document.createElement('input');
$(input).attr({
"type": "Button",
"id": "filterType" + i,
"value": filterUnique[i]
});
document.getElementById("input_filter").appendChild(input);
document.getElementById("filterType"+i).onclick(console.log("test"));
};