javascript - Problems onclick function on child button -
i trying create table, made buttons, allow me geological time chart. create 4 buttons class "levels" , execute function return childs api.
the point function works first time, stop working new created buttons. here 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 problem creating class within function, don't find other solution (i tried declare function , call in .click event, don't work!).
thank of you!!
instead of :
$(".levels").click()
use
$(document).on('click', '.levels', function(){ });
the reason behind is, $(".levels").click()
searches in static dom, , generating button dynamically. dynamic content $(document).on()
used.
Comments
Post a Comment