I am trying to create a table, made with buttons, that allow me to get into a Geological Time Chart. I create 4 buttons with class "levels" and then I execute a function that return the childs from an API.
The point is that the function works the first time, but then it stop working for the new created buttons. Here is my code:
$(".levels").click(function clickLevel(){
var buttonName = $(this).text();
console.log($(this).text());
$.each(JsonObject, function(index,value){
if (buttonName == value.nam){
lvloid = value.oid;
console.log(lvloid);
}
if(lvloid == value.pid){
console.log(lvloid == value.pid);
var button = "<button class=\"btn-flat levels\" style=\"background-color:"+value.col+";\">"+value.nam+"</button>";
$(".conti").append(button);
}
});
});
I guess the problem is that I am creating the class within the function, but I don't find any other solution (I tried to declare the function and then call it in the .click event, but this don't even work!).
Thank you to all of you!!